I linked my project with Github 4 months ago and I today deleted my project unintentionally so I reinstall the last commit from Github and open it in Android Studio but when I make any changes I cannot push it to Github as a master branch but if I push it as different branch it is worked, How can I push the changes as the master branch (default)?
Show details in console
12:48:16.974: [Project] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false push --progress --porcelain origin refs/heads/master:master --set-upstream
error: failed to push some refs to 'https://github.com/.../...'
hint: Updates were rejected because the remote contains work that you do
To https://github.com/.../...
! refs/heads/master:refs/heads/master [rejected] (fetch first)
hint: not have locally. This is usually caused by another repository pushing
Done
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
2
Answers
Select master as your remote branch in Android Studio>Git>Branches>Remote Branches
You can try git push from console it will either work without issue or it will tell you what exact problem is and the alternate command (something like
git push --set-upstream
) to fix it.PS try to learn git basics from any place (youtube / pluralsight) etc and try to use command line as much as you can I have switched to command line for past 2 years and my git understanding is quite improved plus it helps avoid any pesky issues with studio.
Edit – As pointed by the update in question you need to pull the lastest changes by
git pull
before you can push.