Why does my 'git branch' have no master?

Viewed 219555

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?

When I do git branch on the clone that I have, I only see 1 single branch - the one I'm on. No "master" at all. If I type git checkout master (as I see in alot of tutorials or guides), I get

error: pathspec 'master' did not match any file(s) known to git.

I'm just confused as to why my clone doesn't have a master that everyone seems to imply that it always exists.

10 Answers

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

I had the same problem. I executed the "git init", but the main/master branch was not created. Possibly because I used a branch with another name and this one became the default. The solution that worked for me was:

  1. I created the branch "main"

git checkout -b main

  1. I went to the option Settings->Branches of my directory and changed it to the new branch "main" enter image description here

  2. With this change, Github itself notified me that my default branch (main) was behind my other branch and opened the window for me to confirm a PR applying the changes to the branch main. And following this, merging the pull request. enter image description here

Related