Git master branch has no upstream branch

前端 未结 10 738
北荒
北荒 2021-01-30 16:53

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

相关标签:
10条回答
  • 2021-01-30 17:03

    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.

    0 讨论(0)
  • 2021-01-30 17:03

    In case someone is still running into this issue, this command solved it for me

    git push --set-upstream origin master
    
    0 讨论(0)
  • 2021-01-30 17:09

    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
    
    0 讨论(0)
  • 2021-01-30 17:16

    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: enter image description here

    0 讨论(0)
  • 2021-01-30 17:17

    You need to configure the remote first, then push.

    git remote add origin url-to-your-repo

    instructions

    0 讨论(0)
  • 2021-01-30 17:18

    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.

    0 讨论(0)
提交回复
热议问题