Why does my 'git branch' have no master?

前端 未结 9 1124
醉梦人生
醉梦人生 2020-12-12 12:51

I\'m a git newbie and I keep reading about a \"master\" branch. Is \"master\" just a conventional name that people used or does it have special meaning like HEAD

相关标签:
9条回答
  • 2020-12-12 13:15

    In my case there was a develop branch but no master branch. Therefore I cloned the repository pointing the newly created HEAD to the existing branch. Then I created the missing master branch and update HEAD to point to the new master branch.

    git clone git:repositoryname --branch otherbranch
    git checkout -b master
    git update-ref HEAD master
    git push --set-upstream origin master
    
    0 讨论(0)
  • 2020-12-12 13:19

    master is just the name of a branch, there's nothing magic about it except it's created by default when a new repository is created.

    You can add it back with git checkout -b master.

    0 讨论(0)
  • 2020-12-12 13:19

    It seems there must be at least one local commit on the master branch to do:

    git push -u origin master
    

    So if you did git init . and then git remote add origin ..., you still need to do:

    git add ...
    git commit -m "..."
    
    0 讨论(0)
  • 2020-12-12 13:30

    I actually had the same problem with a completely new repository. I had even tried creating one with git checkout -b master, but it would not create the branch. I then realized if I made some changes and committed them, git created my master branch.

    0 讨论(0)
  • 2020-12-12 13:30

    if it is a new repo you've cloned, it may still be empty, in which case:

    git push -u origin master

    should likely sort it out.

    (did in my case. not sure this is the same issue, thought i should post this just incase. might help others.)

    0 讨论(0)
  • 2020-12-12 13:31

    To checkout a branch which does not exist locally but is in the remote repo you could use this command:

    git checkout -t -b master origin/master
    
    0 讨论(0)
提交回复
热议问题