Home > Software design >  Is there a concept of "default branch" in vanilla git?
Is there a concept of "default branch" in vanilla git?

Time:10-13

While there is a concept of "default branch name" in git, I do not see any mention of "default branch" in git documentation or Pro Git book.

However, I do see mentions of "default branch" in git hosting platforms such as GitHub and GitLab.

So, is there a concept of "default branch" in vanilla git? Or is it only a concept used by git hosting platforms?

CodePudding user response:

In git's model, there are no special "server" or "central" repositories. When you clone a repository, then git will by default check out whatever branch is checked out on that other repository. More specifically, it will copy the .git/HEAD file from the other repository into the new clone.

At the most basic, a git server (including hosting platforms such as Github and GitLab) is just what git calls a "bare repository", which contains all the files which would normally be in the .git directory, but no working copy. See the manual for git clone --bare and "Git on the Server" in the Pro Git book.

That means the repository still has a file called HEAD which contains a reference to the "current" branch. When you perform a clone from the server, that is the reference copied to your new .git/HEAD. As such, it acts as the "default branch" for new clones, but in git's terminology it is actually the "current" branch.

Management UIs commonly also use this as a convenient way to set the default branch shown in the file browser, the default target for pull/merge requests, etc.

CodePudding user response:

The closest thing seems to be the init.defaultBranch config entry.

It allows to set which name will be used at git init for the first commit/branch. (see also here)

The default value for this parameter is master.

  • Related