How can I create a Git repository with the default branch name other than "master
"?
You would use Git 2.28 (Q3 2020): the name of the primary branch in existing repositories, and the default name used for the first branch in newly created repositories, is made configurable, so that we can eventually wean ourselves off of the hardcoded 'master
'.
And reminder from Aug. 2020 from GitHub:
On October 1, 2020, if you haven't changed the default branch for new repositories for your user, organization, or enterprise, it will automatically change from master
to main
.
You can opt out of this change at any time:
- For users, on the https://github.com/settings/repositories page
- For organization owners, on the
https://github.com/organizations/YOUR-ORGANIZATION/settings/repository-defaults
page
- For enterprise administrators, on the
https://github.com/enterprises/YOUR-ENTERPRISE/settings/member_privileges
page
This change is one of many changes GitHub is making to support projects and maintainers that want to rename their default branch.
To learn more about the changes we're making, see github/renaming.
But back to Git itself: (2.28, Q3 2020)
See commit 508fd8e (29 Jun 2020) by Đoàn Trần Công Danh (sgn
).
See commit 0068f21, commit a471214, commit 0cc1b47, commit 32ba12d, commit 6069ecc, commit f0a96e8, commit 4d04658 (24 Jun 2020), and commit 489947c (23 Jun 2020) by Johannes Schindelin (dscho
).
See commit 8747ebb (24 Jun 2020) by Don Goodman-Wilson (DEGoodmanWilson
).
(Merged by Junio C Hamano -- gitster
-- in commit 11cbda2, 06 Jul 2020)
init
: allow specifying the initial branch name for the new repository
Signed-off-by: Johannes Schindelin
There is a growing number of projects and companies desiring to change the main branch name of their repositories (see e.g. Mislav Marohnić's tweet for background on this).
To change that branch name for new repositories, currently the only way to do that automatically is by copying all of Git's template directory, then hard-coding the desired default branch name into the .git/HEAD
file, and then configuring init.templateDir
to point to those copied template files.
To make this process much less cumbersome, let's introduce a new option: --initial-branch=<branch-name>
.
git init --initial-branch=hello myLocalRepo
# or
git config --global init.defaultBranch hello
git init myLocalRepo
And:
init
: allow setting the default for the initial branch name via the config
Helped-by: Johannes Schindelin
Helped-by: Derrick Stolee
Signed-off-by: Don Goodman-Wilson
We just introduced the command-line option --initial-branch=<branch-name>
to allow initializing a new repository with a different initial branch than the hard-coded one.
To allow users to override the initial branch name more permanently (i.e. without having to specify the name manually for each and every git init
invocation), let's introduce the init.defaultBranch
config setting.
Note: commit 489947c, about the merge commit message, has since been reverted in Git 2.29, see "how can I customize git's merge commit message?".
The init.defaultBranch
setting remains.
This impacts submodules:
submodule
: fall back to remote's HEAD for missing remote..branch
Helped-by: Philippe Blain
Signed-off-by: Johannes Schindelin
When remote.<name>.branch
is not configured, git submodule update
currently falls back to using the branch name master
.
A much better idea, however, is to use the remote HEAD
: on all Git servers running reasonably recent Git versions, the symref HEAD
points to the main branch.
Note: t7419 demonstrates that there might be use cases out there that expect git submodule update --remote
to update submodules to the remote master
branch even if the remote HEAD
points to another branch.
Arguably, this patch makes the behavior more intuitive, but there is a slight possibility that this might cause regressions in obscure setups.
Even so, it should be okay to fix this behavior without anything like a longer transition period:
- The
git submodule update --remote
command is not really common.
- Current Git's behavior when running this command is outright confusing, unless the remote repository's current branch is
master
(in which case the proposed behavior matches the old behavior).
- If a user encounters a regression due to the changed behavior, the fix is actually trivial: setting
submodule.<name>.branch
to master
will reinstate the old behavior.
Note that, with Git 2.29 (Q4 2020), tests in contrib/
are adjusted to the recent change to fmt-merge-msg
.
See commit b87528c (03 Aug 2020) by Emily Shaffer (nasamuffin
).
(Merged by Junio C Hamano -- gitster
-- in commit 83b8250, 10 Aug 2020)
Revert "contrib
: subtree
: adjust test to change in fmt-merge-msg
"
Signed-off-by: Emily Shaffer
This reverts commit 508fd8e8baf3e18ee40b2cf0b8899188a8506d07.
In 6e6029a8 (fmt-merge-msg
: allow merge destination to be omitted again) we get back the behavior where merges against 'master
', by default, do not include "into 'master'
" at the end of the merge message. This test fix is no longer needed.
Also:
With Git 2.29 (Q4 2020), update the tests to drop word 'master
' from them.
See commit f33f2d3, commit b6211b8 (26 Sep 2020), and commit 432f5e6, commit 5a0c32b, commit 659288c (21 Sep 2020) by Johannes Schindelin (dscho
).
(Merged by Junio C Hamano -- gitster
-- in commit 58138d3, 05 Oct 2020)
tests
: avoid variations of the master
branch name
Signed-off-by: Johannes Schindelin
The term master
has a loaded history that serves as a constant reminder of racial injustice. The Git project has no desire to perpetuate this and already started avoiding it.
The test suite uses variations of this name for branches other than the default one. Apart from t3200, where we just addressed this in the previous commit, those instances can be renamed in an automated manner because they do not require any changes outside of the test script, so let's do that.
Seeing as the touched branches have very little (if anything) to do with the default branch, we choose to use a completely separate naming scheme: topic_<number>
(it cannot be topic-<number>
because t5515 uses the test_oid
machinery with the term, and that machinery uses shell variables internally, whose names cannot contain dashes).
This trick was performed by this (GNU) sed invocation:
$ sed -i 's/master\([a-z0-9]\)/topic_\1/g' t/t*.sh
And, still with Git 2.29:
See commit 538228e, commit a15ad5d (08 Oct 2020) by Johannes Schindelin (dscho
).
(Merged by Junio C Hamano -- gitster
-- in commit 62564ba, 08 Oct 2020)
t1415
: avoid using main
as ref name
Signed-off-by: Johannes Schindelin
In preparation for a patch series that will change the fall-back for init.defaultBranch
to main
, let's not use main
as ref name in this test script.
Otherwise, the git for-each-ref ... | grep main
(man) which wants to catch those refs would also unexpectedly catch refs/heads/main
.
Since the refs in question are worktree-local ones (i.e. each worktree has their own, just like HEAD
), and since the test case already uses a secondary worktree called "second
", let's use the name "first
" for those refs instead.
While at it, adjust the test titles that talk about a "repo" when they meant a "worktree" instead.