'Git master branch has no upstream branch
I'm trying to push one of my projects to github, and I keep getting this error:
fatal: The current branch master has no upstream branch.
I've never seen this before. I re-initialized my git, re-added my origin, deleted and re-made the repo, and recreated my SSH key.
Solution 1:[1]
Create the repo on github; add a README file on github and then clone the github repository. Creating the README file (or any file actually) is needed in order to get a master branch.
Notice how github prompts for creating a README when creating a repository:

Solution 2:[2]
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).
Solution 3:[3]
The following command worked for me:
git branch --set-upstream-to=origin/master master
Solution 4:[4]
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
Solution 5:[5]
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
Solution 6:[6]
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.
Solution 7:[7]
Cool Blue's answer ALMOST worked for me.
First I did: "git branch --set-upstream-to=origin/master master", as recommended by Cool Blue.
But still received error message:
"failed to push some refs to ''
hint: Updates were rejected because the tip of your current branch is behind its remote counterpart. Integrate the remote changes (e.g. 'git pull ...') before pushing again."
So I... did a "git push -f" command after the git branch, which worked finally worked for me.
After the forced push, subsequent "git push" commands worked without issue.
Solution 8:[8]
In case someone is still running into this issue, this command solved it for me
git push --set-upstream origin master
Solution 9:[9]
Try both the HTTP and SSH urls? I had a problem when I was using the SSH url but, when I switched to the HTTP one, it worked like a charm.
Here is what I changed:
First, view the remote URL
git remote -v
and you get destinations back.
git remote rm destination
Follow this link if you need help: https://help.github.com/articles/removing-a-remote/
Then,
git remote add origin url
git push -u origin master
Solution 10:[10]
git push -u origin master has been deprecated.
Use git config --global push.default current instead
Solution 11:[11]
You need to configure the remote first, then push.
git remote add origin url-to-your-repo
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
