Why does my 'git branch' have no master?

前端 未结 9 1125
醉梦人生
醉梦人生 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:33

    If you create a new repository from the Github web GUI, you sometimes get the name 'main' instead of 'master'. By using the command git status from your terminal you'd see which location you are. In some cases, you'd see origin/main.

    If you are trying to push your app to a cloud service via CLI then use 'main', not 'master'.

    example: git push heroku main

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

    Most Git repositories use master as the main (and default) branch - if you initialize a new Git repo via git init, it will have master checked out by default.

    However, if you clone a repository, the default branch you have is whatever the remote's HEAD points to (HEAD is actually a symbolic ref that points to a branch name). So if the repository you cloned had a HEAD pointed to, say, foo, then your clone will just have a foo branch.

    The remote you cloned from might still have a master branch (you could check with git ls-remote origin master), but you wouldn't have created a local version of that branch by default, because git clone only checks out the remote's HEAD.

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

    I ran into the same issue and figured out the problem. When you initialize a repository there aren't actually any branches. When you start a project run git add . and then git commit and the master branch will be created.

    Without checking anything in you have no master branch. In that case you need to follow the steps other people here have suggested.

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