When you clone some existing repository, you get all of their commits 1 and none of their branch names. But they still do have branch names. What your Git does with those is turn them into your own remote-tracking names.2
A remote-tracking name like origin/master
or origin/main
is your Git's way of remembering one of their Git's branch names.3 So if they have a branch named main
, you get a remote-tracking name origin/main
. If they have a branch named master
, you get a remote-tracking origin/master
.
Once git clone
has finished copying their commits into your repository, and renaming their branch names to your remote-tracking names, your Git then creates one branch name in your repository. You choose which branch name your Git should create, using the -b
option to git clone
:
git clone -b develop https://example.com/path/to/repo.git
for instance.
If you don't give a -b
option, your Git asks their Git which name they recommend. Depending on who "they" are, they may recommend either master
or main
.
There's one thing that's a bit peculiar here, and that is that your Git demands that this name you select match one of their names. Since your names are yours, and their names are theirs, and the two need not match up,4 there is no real requirement for this, but your Git still demands it anyway, probably in an attempt to reduce confusion. So if they have only main
, or only master
, that's the name you'll get.
The (single) standard first name used to be master
. Then GitHub changed theirs to main
and now there is confusion. If you create a repository from scratch—rather than cloning it—you can choose any initial branch name you want.5
1Technically, you can get fewer than all of their commits, but the usual case is that you get them all.
2Git calls these remote-tracking branch names, but they are not branch names: git switch origin/main
gives you an error, for instance, and git checkout origin/main
produces what Git calls a detached HEAD. Meanwhile, the word branch is very badly over-used in Git. So it makes more sense to drop the word branch from this phrase. These names are just names in your repository that remember someone else's branch names; we could call them "crimson names", but they do in fact track some "remote" Git's branch names, so remote-tracking is sort of reasonable.
3By "your Git", I mean "your Git software, working within your repository". "Their Git" is thus their software working within their repository.
4That is, you can call one of your branches dwayne
while they call one of theirs rapunzel
, and yet you can still make your commits on your dwayne
match up with theirs on their rapunzel
. It's just ... confusing to do this. Humans seem to prefer to use the same name on both sides when the goal is to have the same commits on both sides too.
This idea can go awry: if you have two different remotes, such as bob
to connect to Bob's Git and alice
to connect to Alice's, and both bob
and alice
have a branch named cream
but one refers to a dairy product and the other to the 1960s band, you're not going to be able to have one branch in your repository named cream
that somehow works for both of these. So Git doesn't require it, except during this initial git clone
step.
5This requires a reasonably up-to-date Git to do it with the git init
command. With older versions of Git, you do the git init
and get started with the name master
, then rename the branch.