Failed to publish this branch.
I received the above error while trying to commit and push a new project into a GitHub repository.
I went back to my repository in the GitHub client, right clicked on it and choose “open a shell here”. In the shell I entered “git push” and received a more explanatory error message which was:
“fatal: The current branch master has no upstream branch.”
I assumed this meant it can’t publish the branch (even the master) because there is no master branch currently in my new repository. I assumed it would go ahead and create that branch for me but I guess that’s not the case. Based on a StackExchange article I found I used the following command to try to push the initial commit into the master branch:
git push –u origin master
... which, gave me this error message “failed to push some refs to ‘my repository’” and hints:
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
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.
So, the only thing that was in my repository on the server was the README.md file and apparently I can’t commit my changes to everything else without getting that first. So… I issued this command:
git pull origin master
Now, this brought down the only file in the repository (which I didn’t have locally because it was created with the repository when I created it through the front end). After doing this I was able to publish my code up to GitHub.