8 ms·
> Git doesn't have the concept of "main is special" Technically, there is special handling for both "master" and "main" in Git in fairly obvious, but I'd argue
by andrybak 3y ago
> Git doesn't have the concept of "main is special"
Technically, there is special handling for both "master" and "main" in Git in fairly obvious, but I'd argue in a not very important way. When you merge two regular branches, the commit message is `Merge branch 'source' into destination`. But not if destination is `master` or `main` – the `into ...` part is omitted for those merge commits.
But this is just for backward compatibility. Git is very conservative in changing such user facing behavior as generated merge commit messages. To get Git to treat `master` and `main` truly without special handling, set empty value to config option `merge.suppressDest` [1]:
$ git config merge.suppressDest ""
`master` is also used as the default name for the default branch in newly created repositories. See option `--initial-branch` of `git init` and config variable `init.defaultBranch` [2] to override. Git for Windows, for example, allows setting the config option in its installer.
Source code:
For merge commit formatting: https://github.com/git/git/blob/2108fe4a1976f95821e13503fd331f075da398c6/fmt-merge-msg.c#L646-L649 https://github.com/git/git/blob/2108fe4a1976f95821e13503fd33...
For default branch naming: https://github.com/git/git/blob/91e2ab1587d8ee18e3d2978f2b7bc250faf5df8f/refs.c#L662-L686 https://github.com/git/git/blob/91e2ab1587d8ee18e3d2978f2b7b...
Git for Windows installer suggesting setting `init.defaultBranch`:
- https://github.com/git-for-windows/build-extra/blob/586c46eca4c47dc9d596d0465c1f06451f2ea8c8/installer/install.iss#L2026-L2053 https://github.com/git-for-windows/build-extra/blob/586c46ec...
- https://github.com/git-for-windows/build-extra/blob/586c46eca4c47dc9d596d0465c1f06451f2ea8c8/installer/install.iss#L3219-L3224 https://github.com/git-for-windows/build-extra/blob/586c46ec...
Footnotes:
[1] https://git-scm.com/docs/git-merge#Documentation/git-merge.txt-mergesuppressDest https://git-scm.com/docs/git-merge#Documentation/git-merge.t...
[2] https://git-scm.com/docs/git-init#Documentation/git-init.txt--bltbranch-namegt https://git-scm.com/docs/git-init#Documentation/git-init.txt...
- chrnola 3y agoThere’s some special handling for FETCH_HEAD too (i.e. which branch on a remote is considered the default).
- andrybak 3y ago> which branch on a remote is considered the default You probably mean this place in code: [1]. It uses function git_default_branch_name from refs.c [2], which uses config variable `init.defaultBranch` I've mentioned above. But if it and other look-ups fail, it does fall back to a hard-coded "refs/heads/master". [1] https://github.com/git/git/blob/v2.43.0/remote.c#L2380-L2394 https://github.com/git/git/blob/v2.43.0/remote.c#L2380-L2394 [2] https://github.com/git/git/blob/v2.43.0/refs.c#L671-L705 https://github.com/git/git/blob/v2.43.0/refs.c#L671-L705 Edit: removed mention of a deprecated Git feature to avoid confusion.