init: allow setting the default for the initial branch name via the config

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.

Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Helped-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Don Goodman-Wilson <don@goodman-wilson.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Don Goodman-Wilson
2020-06-24 14:46:33 +00:00
committed by Junio C Hamano
parent 32ba12dab2
commit 8747ebb7cd
5 changed files with 57 additions and 1 deletions

View File

@ -269,7 +269,7 @@ static int create_default_files(const char *template_path,
char *ref;
if (!initial_branch)
initial_branch = "master";
initial_branch = git_default_branch_name();
ref = xstrfmt("refs/heads/%s", initial_branch);
if (check_refname_format(ref, 0) < 0)