Cosimo Sguanci
Cosimo Sguanci

Reputation: 1291

Android Studio Git Push Rejected

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:

Upvotes: 58

Views: 91603

Answers (16)

Narandhran Thangavel
Narandhran Thangavel

Reputation: 1410

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.

Upvotes: 96

Tarun Anchala
Tarun Anchala

Reputation: 2702

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

Upvotes: 0

Mustafa Tameemi
Mustafa Tameemi

Reputation: 1176

I had the same problem, just solve it by doing this:-

Go to Github account settings

(1)

enter image description here

(2) enter image description here

Upvotes: 2

Amr Jyniat
Amr Jyniat

Reputation: 385

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.

Upvotes: 0

Sumit Shukla
Sumit Shukla

Reputation: 4494

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

Upvotes: 18

MSI Abu Zafar Newton
MSI Abu Zafar Newton

Reputation: 682

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

enter image description here

This will eradicate all your contradicting configurations.

Upvotes: 11

HeshanHH
HeshanHH

Reputation: 703

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

Upvotes: 0

Aishwarrya Varshney
Aishwarrya Varshney

Reputation: 1

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:

  1. Right click on project name and go to Repository option.
  2. Then select Remotes.
  3. 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.

Upvotes: 0

Rishi Joshi
Rishi Joshi

Reputation: 11

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.

Upvotes: 1

Rithik Sabhal
Rithik Sabhal

Reputation: 59

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

Upvotes: 0

tamon76
tamon76

Reputation: 19

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

Upvotes: 1

Ali mohammadi
Ali mohammadi

Reputation: 1899

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

Upvotes: 0

Blasanka
Blasanka

Reputation: 22417

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.

Upvotes: 0

Programmer X
Programmer X

Reputation: 53

If none of the above solution works then you can check this out..

  1. Log in to the GitHub account and go the settings.
  2. In settings open Emails section and check whether it is public or private.
  3. 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.

  1. Open the project tab(must be in the left side toolbar, if not then press 'Alt + F1')
  2. At the top, there is a dropdown with 'Android', open the dropdown and select the 'Project'
  3. In the list shown, right click your project folder
  4. There must be a option of 'Git', select it
  5. 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 :)

Upvotes: 5

Sunil
Sunil

Reputation: 3793

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

Upvotes: 7

SamTh3D3v
SamTh3D3v

Reputation: 9944

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)

enter image description here

after that you can Git > Push without problem.

Upvotes: 93

Related Questions