by andrybak · 3y ago · 0 comments
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/2108fe4a1976f95821e13503fd33...
For default branch naming: https://github.com/git/git/blob/91e2ab1587d8ee18e3d2978f2b7b...
Git for Windows installer suggesting setting `init.defaultBranch`:
- https://github.com/git-for-windows/build-extra/blob/586c46ec...
- https://github.com/git-for-windows/build-extra/blob/586c46ec...
Footnotes:
[1] https://git-scm.com/docs/git-merge#Documentation/git-merge.t...
[2] https://git-scm.com/docs/git-init#Documentation/git-init.txt...
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
[2] https://github.com/git/git/blob/v2.43.0/refs.c#L671-L705
Edit: removed mention of a deprecated Git feature to avoid confusion.