0

I have shared my project to GitHub. I have just started using GitHub and I am not knowledgeable about Git in general, just following online tutorials. Each time I push to GitHub I get an error: push to origin/master was rejected. I searched online and, as I understand it, the files in the remote repository must have changed. But I am the only one connected to my repository and it is set to Private.

I did not change the files in GitHub and no one could have changed it. But each time I make edits to my local files in Android Studio and push it, I always get the same error.

P.S.: I'm using the GUI, not the Terminal.

I tried deleting my repository, shared my local project again, update my code, then push, but I get the same error, again.

Kellin Strook
  • 487
  • 1
  • 5
  • 18
  • do you see more details apart from ```error: push to origin/master was rejected```? – Kundan Apr 21 '20 at 15:21
  • not really. I use the GUI so the error appeared in a dialog. – Kellin Strook Apr 21 '20 at 15:32
  • Can you try to run ```git push``` command using git bash from the root of your project where there is .git folder present (might be hidden) & share the result – Kundan Apr 21 '20 at 15:35
  • FYI at the time of comment 15-20 minutes earlier the github website server were down and showing `504 Gateway Time-out error`. Could you try now and check! – ArifMustafa Apr 21 '20 at 15:51
  • @ArifMustafa It's fine now. But at the time of comment, I have experienced the error three (3) times already, on three separate days. I read that I need to checkout the master or something, and some post that checkout was no longer necessary (it was necessary back then but Git has now evolved, or so I remember). This is actually confusing. Thanks for the comment though. – Kellin Strook Apr 23 '20 at 12:28

3 Answers3

0

Same happened to me. Seems the problem could be there are some files in your GitHub repository.

Create a new blank repository on Git.

On Android Studio you need to VCS -> Import into version control -> Create Git Repository...

If above works, Commit and Push your files to GitHub.

If not, create a backup of your source code folder.

After that rename your folder.

Copy your files into the recently created new folder (except the .git sub-directory)

Try again with the VCS -> Import into version control -> Create Git Repository... to the new folder.

It worked for me before some attempts and I could Push my work to GitHub. Hope it helps.

0

Lets say your branch name is name_of_branch In case if you see a Git -> Console -> log message saying.

refs/heads/name_of_branch:refs/heads/name_of_branch [remote rejected] 
(cannot lock ref 'refs/heads/name_of_branch': 'refs/heads/name' exists; 
cannot create 'refs/heads/name_of_branch'

This means there is some issue with branch name somehow. I solved it by renaming my branch.

VCS -> Git -> Branches -> select your branch and rename

Vijay E
  • 829
  • 10
  • 14
-1

I had such an issue too and I clicked the tab of Git on the lower left of Android Studio and then selected "console", I saw [remote rejected] (push declined due to email privacy restrictions).

I then referred to the following thread:

Error "Your push would publish a private email address"

-----------Addition------------

The error message could also look like this:

Successfully created project '(your project name)' on GitHub, but initial push failed: Enumerating objects: 10, done. Delta compression using up to 4 threads Total 10 (delta 0), reused 0 (delta 0), pack-reused 0 remote: error: GH007: Your push would publish a private email address.

or

remote: You can make your email public or disable this protection by visiting: remote: http://github.com/settings/emails failed to push some refs to 'xxx.git'