Git master branch has no upstream branch
Instead of creating a new repository on Github, cloning that, or reinitializing your local repository, the following command would have been sufficient:
git push -u origin master
origin
stands for the remote name (default is origin),master
is the branch you want to push, in your case it's master, otherwise you would have to change that in the command.-u
means, that your local branch will be setup to track the new created master branch on the origin repository (the master on the origin will be the upstream branch of your local branch). If the branch master doesn't exist on the remote repository, it will be created, otherwise it will be updated (the -u
works no matter if it exists or not).
The following command worked for me:
git branch --set-upstream-to=origin/master master
i faced the same problem just tell github to use the current head branch of your local repository:
git push --set-upstream origin master
wish it help you and others
I had this problem today on my own remote repository, not Github and realized I had not made any commits to my local repository before trying to push to the remote repository.
git add -A
git commit
git push origin master
Some people coming to this page may simply have this error because they did git push origin
and simply didn't realise that you need to specify the remote branch name as well, as in git push origin master
.
If you do git branch --set-upstream-to=origin/master master
a reference is added to .git\config to link the local and remote branches. I presume that then you no longer need to specify the branch name when pushing to the remote.