git 的哪些部分对名为 "master" 的分支有特殊/默认行为?

What parts of git have special / default behaviours for a branch named "master"?

鉴于有 no wide agreement on the semantics of master,我们正在考虑在我们的 origin 服务器上完全没有名为 master 的分支。

就标准 git 命令行客户端中内置的默认值而言,这会产生什么后果?它如何将名为 master 的分支与其他分支(本地分支和远程分支)区别对待?

master在某些地方被用作默认值。

  • 空存储库中的第一个分支在 master 分支中完成。
  • 当 y != master
  • 时,合并提交消息是 "Merge branch x" 或 "Merge branch x into y"

但是除了这种东西之外,一个名为 master 的分支并不是真正必要的。

根据我对代码库的调查以及我对没有 master 分支的存储库的经验,我想你是清楚的。

最坏的情况是,在一些边缘情况下,不明确会导致命令失败,而不是回退到 master 分支。


  • git clone 在未找到远程引用且未指定 --bare 标志时默认设置 master 分支 (builtin/clone.c)
  • git fast export--anonymize 标志单独留下 master,因为它是众所周知的默认值并且不传达任何信息 (built-in/fast-export.c)
  • 合并提交消息是根据目标分支定制的(即 "Merge branchx" 与 "Merge branchx into branchy")(builtin/fmt-merge-msg.c
  • git init 使用 master 作为默认分支名称 (builtin/init-db.c)
  • git submodule 在未指定分支名称时默认为 master (builtin/submodule--helper.c)

(下面的 git-remote.cfiles-backend.c 输出实际上并不与 master 分支交互)


上面的列表是在 git repository.

上使用以下 git grep 编译的
# Look for string literals within *.c files containing "master" 
# with 10 lines of context, excluding the t/ and contrib/ directories
$ git grep -C 10 -E -e \".*master.*\" -- :**/*.c :^t/ :^contrib/