Reputation: 241
Are all branches in Git equal or is master different somehow? I don't mean the logical position we give it in the hierarchy. I mean, is there some underlying code that treats a master branch differently from the way it treats a feature branch?
Upvotes: 3
Views: 155
Reputation: 489468
There are a bunch of relatively minor special cases for master
in the git source code. Clone the git source and run git grep master
to see all of them (note that many are just release notes). Here are a few samples:
builtin/fast-export.c: * We also leave "master" as a special case, since it do
builtin/fast-export.c: if (!strcmp(refname, "refs/heads/master"))
These bits in fast-export are for anonymizing names (see the manual); branch master
does not get anonymized.
builtin/fmt-merge-msg.c: if (!strcmp("master", current_branch))
This is the default merge message: "merge branch X into Y"; the "into Y" part is omitted when Y is master
.
Upvotes: 6
Reputation: 32260
A branch is a branch, no matter which name it has. The only difference is when you talk about remote-tracking branch.
Quoting the official documentation:
“origin” is not special Just like the branch name “master” does not have any special meaning in Git, neither does “origin”. While “master” is the default name for a starting branch when you run git init which is the only reason it’s widely used, “origin” is the default name for a remote when you run git clone. If you run git clone -o booyah instead, then you will have booyah/master as your default remote branch.
The remote-tracking branch is just a local reference to a branch present in a remote repository. You can't control it directly - It's updated automatically for you whenever you do a network operation.
Quoting the relevant part from the documentation:
Remote-tracking branches are references to the state of remote branches. They’re local references that you can’t move; they’re moved automatically for you whenever you do any network communication. Remote-tracking branches act as bookmarks to remind you where the branches in your remote repositories were the last time you connected to them.
The current branch (the one you're working on) is known as HEAD, which is just a special pointer (reference) file. It means when you do a git checkout <branch>
it's updated to point to the informed branch.
Upvotes: 5
Reputation: 6509
The head branch is special. That is the thing pointed to by repository/.git/HEAD is used as a default branche when you clone the repository. Besides that, all branches are equal.
Upvotes: 3