Android Studio Git Push Rejected - android

I'm trying to uploading my Android Project on github but I get this error when I try to push:
Push rejected: Push to origin/master was rejected
I made this steps:
VCS->Import into version control->Create new repository...
From the git bash in Project folder:
git remote add origin https://github.com/[username]/[project_name].git
Git->Add
Git-> Commit directory
Git-> Push

after push follow these,
VCS --> Git --> Branches
then select origin/master --> Rebase
after finish rebase successful message, you could able to push to remote directory.

As suggested in the comments you should pull the changes first, if you are working on a new repository that could happened when you create your remote repo with a readme or a licence file. To pull the changes from the user interface you should use, VCS > Git > Pull then select the master branch (depends)
after that you can Git > Push without problem.

Just go to the root directory of your project and follow below steps:
Right Click-> Git Bash Here
Type git init (For initializing git).
Type git add -A (Get all files in the staging area).
Type git commit -m "First Commit"(Commit Changes)
Type git remote add origin https://your_git_url.git (Your repo URL)
Type git push -u origin master(master - Branch name)
OR
Type git push -f origin master(master - Branch name) (-f for Force push and make sure there are no changes in your branch to push code.)
You can also make use of Git GUI client:
Github Desktop for github users Download
GitKracken for Windows, Mac and Linux Download (Free for public repositories)
SourceTree for Windows and Mac Download

For Android Studio if your "Push" is rejected, go ahead and try this:
Try to Pull.(Origin/Master).Right after that:
VCS-->Git-->Branches..-->Remote Branches(origin/master)-->Rebase Current onto Selected
This will eradicate all your contradicting configurations.

Try this
This type of error was also coming in my project because i have create a new project and paste my old config and some classes file in new project.
I have pushed the code by creating new branch
Go to VCS->Git->Branches->New Branch

If none of the above solution works then you can check this out..
Log in to the GitHub account and go the settings.
In settings open Emails section and check whether it is public or private.
If it is public then other solution will work out finely and if your email is private then declare it public.
Because of the private email you aren't able to push the files in the repository from your IDE. So, make it public
Another Solution.!!
The unversioned code is not versioned, the changes are committed but don't push.
Following are the steps to make the files versioned.
Open the project tab(must be in the left side toolbar, if not then press 'Alt + F1')
At the top, there is a dropdown with 'Android', open the dropdown and select the 'Project'
In the list shown, right click your project folder
There must be a option of 'Git', select it
Choose the 'Add' option.
And there it is!.
Now simply try to commit and push operation as usual.
**NOTE :**You've to add files everytime using the above steps to upload the files successfully.!!
Thank you folks :)

I had this same problem. I finally tried it from the command line and and received this message:
remote: error: GH007: Your push would publish a private email address.
remote: You can make your email public or disable this protection by visiting:
remote: http://github.com/settings/emails
There you should see two checkboxes. You will need to uncheck one of them.
Keep my email address private
Block command line pushes that expose my email

This is the case when you make a repository with a readme file default and so you can either pull first or make a new repository without a readme file and dont forget to change the repo URL. Hope it helps. Cheers.

I had the same problem, just solve it by doing this:-
Go to Github account settings
(1)
(2)

I had the same issue when I Fork from my another github account and clone it in Android Studio, I changed some file and commit(success) and pushed and that is rejected.
The problem was, I have logged into GitHub in Android Studio with my other account, not the one I'm fork the project. Check out your's from:
File -> Setting -> Version Control -> GitHub
If account information is not match with the repo cloned account, change it.
Then you can Push without a problem.

We can get around this "limitation" by editing the .git/config on the destination server. Add the following to allow a git repository to be pushed to even if it is "checked out":
[receive]
denyCurrentBranch = warn
or
[receive]
denyCurrentBranch = false

If you are pushing for the first time, Delete the repository from git, Share the project again on Git from Android Studio 3

When I encountered the same error in Android Studio; I just simply renamed my remote name and it fixed the error.
Steps which I followed are:
Right click on project name and go to Repository option.
Then select Remotes.
Then you will be asked to Define Remote by providing a name of the remote and URL of your GitHub repository. Just change the name according to your choice if 'origin' is already filled and then fill the URL of your GitHub repository.

I am giving clear note here skip steps you already done..
first create new repository in github. (dont close the tab until work done)
then you have to check whether you are log into your github account in android studio. if not you can log in setting-->Version Control --> github.
Then go to VCS -> Import into Version Control.
now in android studio project tab change it from android to project .Android to Project.
step 3:
then Right click on your project select git then +add. again Right click -> commit and again Right click -->git--> repository--> push.
in the new window select origin ->master then push.. if you already do this part and get the error in here do this.(i think this is the first time you try to add your project to github and github repo is empty.)
goto terminal (bottom of the ide) remove origin using this command.
git remote rm origin
now do step 3 again. after that you will asked to enter github repository url.
whenever you add url make sure to add .git .at the end of the url.
like this. https://github.com//xylophoneApp.git

for anyone maybe Suffers with this issue like me, the entire problem was with executionHistory.bin file, and don't ask me why because I don't know at all.
just create commit without this file and push it, this was the solution for my issue.
Hope this help someone.

In my case initially, I had created a new repository with a Readme file.That's causing the issue. Next time when I create new repo without the Readme file, everything works fine

Related

how to fix the red class to green can be pushed on github

how to fix the red class to green can be pushed on github, every time I go to github, I don't go to push because it's still red, after editing it's usually green
If files are Red means files are not added to Git.To Add files to git follow below steps
Steps for Add files to git:
Select File which is need to add,next write click on file -> Git->Add
Please refer below screenshot for adding files to git:-
After follow these steps now you can commit and push the files to git.
Steps for Commit files:
Click on VCS->Commit
Refer below screenshot for Commit:-
I hope it works for you
The below file is red because its not added to your git repository.
for adding and committing it to the git repository you must add->commit->push.
There are multiple ways to do so, one way is using the Gui controls available in the android Studio or using the Command line commands.
Below screenshot shows how it is done in android studio.
You can Commit and Push the files whichever you want to be updated in the repository.
Commands to update your new files into repository are :
git stash
git pull
git stash apply
//resolve your conflicts
git add <filename>
git commit -m "<commit message>"
git push
it because you just create a new file and not insert into the commit file, if you binding your git into android studio select VCS -> GIT -> Commit File.
Then on the dialog make sure you have already a checkmark on the file still red, then you can commit the file, after you do that, that will become green when you have changes on your file.
Solved
right clicked the file -> GIT -> Add.

How to put an Android Project on Github?

I was trying to use Android Studio's in built VCS but was getting some error. I recently learned that it can be done using Git also. Can anyone tell me how to do that ?
Try this:
git init (unless you have already done so)
git config user.name "someone"
git config user.email "someone#someplace.com"
git add *
git commit -m "some init msg"
Note that the email you use should be the same as the one associated with your GitHub account.
Alternatively you can use Tools like SourceTree to configure. It is quite easy to configure and perform git operation using sourceTree.
https://www.sourcetreeapp.com/

How to delete a repository and add a new one in Android studio?

I was working with VCS enabled in Android Studio and pushed my code to a repository that I had created in BitBucket. However, now the team I'm working with has created a new repository also on BitBucket and I have to switch my entire project there. So how do I stop VCS in my current project, and push code to a new repoositroy with a new link from scratch?
Also, in the first repository that I was working with only the "java" folder was pushed and not the rest. Now in the new repository I want to be able to commit and push changes made in all other files as well like "res" etc.
U can remove connection from git repository.
step 1 :Open git bash.
step 2 : navigate to the master folder. '
step 3 : $ git remote rm origin
The git remote will now be removed from the repository.
Now u can add new connection by using VCS->Git->+add.
[Remove and add git]
or you can add/edit remote url
VCS -> Git -> Remotes...

Trying to use Git with Android Studio

With a friend we were a long time trying to work with Git and Android Studio, but we had a problem (we are very new to git and Android Studio, we started a couple of days ago on both issues).
What happens to us is that, for example, if I cloned the git repository and I try to make a merge, then the button to execute is grayed out and it doesn't let me compile or run it, also if I display the project structure as Android or Packages I see nothing, I can only see the files in Project, Project Files, Recent Changes, etc...
I will explain in detail everything we've done.
First, the repository looks like this (p and c are just the initials).
x (c)
/
x (master)
\
x (p)
Master has the first initial commit with .gitignore and README.md, nothing more, while we (me who created the branch p, and my friend who created the branc c) have just one commit each one with executable projects, although I'm not interested in joining what I've done with what my friend has done, I just want to start a new project of Android Studio with what my friend has made.
So I start Android Studio, "Check out project from Version Control -> GitHub", I put my key and choose the repository I want to clone, after that AS ask me if I want to create a new project and I click Yes.
I hit next until the new project is created and here I can see all the branches that we have created on GitHub.
After that I make a local branch to try to work with the project of my friend, with the option "Git branches -> New Branch" and calling it p, which moves me to this local branch automatically.
After that, I choose the Merge option of the remote branch origin/c, and I get a merge failure, that says "Some untracked working tree files would be overwritten by merge. Please move or remove them before you can merge.", I choose the option to view the files and it shows me these.
Since my project is completely new, and the project that my friend uploaded worked fine for him, I just deleted these files with the red bar that my mouse is pointing and after that a message appears that says there is no difference now.
Finally, after that, I go again to the merge option of the remote branch c, and a conflict message appears, which is on the .gitignore file, in my case I put to "Accept Theirs", and I see the message that the merge was correctly.
And now it is when I see that the button to execute is grayed and if I display the project structure as Android I see nothing, I can only see the files in Project, Project Files, etc...
I think it should be something super basic what I'm asking, but we (me and my friend) had never worked with git or android studio and now we are asked to make a project using them.
This is because you have added .idea folder in your git repository.Sample .gitignore file can be like this
build/
.gradle/
*.iml
.idea/
src/main/gen/*
*~
*.swp
local.properties
*.keystore
*.keystore.password
Also you need to delete this folder from git repo. You can use below command
git rm -rf .idea/
git commit -m "deleting .idea, updated .gitignore"
Then try to merge
Followed by #Akhil's answer, click "Make Project" icon to awake your Run button. Sometimes this button makes Android Studio recognize your project runnable again.

eGit move project to a different location?

I was working on an Android project in Eclipse and I then decided to Git it. Being new, instead of creating a local repository in the parent of the project, I ended up creating it in C:\Users\Little\.git\LocalRepository.
Now, I am facing a lot of problems in my Android project; specifically with adding user libraries to my build path.
Based on this answer here:
Eclipse will not recognize project as library (ActionBarSherlock/ViewPagerIndicator)
I have imported all the user libraries to my workspace. However, my project itself is in a different folder and hence I am stuck. There is also a comment on the answer which says:
Thanks. In my case, I forgot that my project was imported from git and
was physically located in another folder than all other projects.
I believe I have to do the same. How do I get the project from local repo to my workspace?
May be below command help someone to get rid of same issue with command line :
Step 1 : To make sure that ur git does not contains any local changes do :
git status
make sure here there is files where u have changes something and is in red color
Step 2: To check when and how commited last do :
git log
Step 3 :
rm -rf .git
Make sure u just take backup.
Step 4 : do git clone to dir u need :
git clone ssh://firstname.lastname#xx.x.xx.xx:xxxxx/project_name

Categories

Resources