Junio C Hamano <gitster@xxxxxxxxx> writes: > "Johannes Schindelin via GitGitGadget" <gitgitgadget@xxxxxxxxx> > writes: > ... >> This series DOES NOT change the default automatically, but only provides an >> opt-in mechanism for interested users. It also presents a way forward for >> such a transition, if and when we decide to do so. Specifically, the new >> GIT_TEST_DEFAULT_BRANCH_NAME environment variable could be used to update >> test scripts on an individual basis instead of all-at-once. > > Yes. I've been thinking about a way that does not hurt workflows > used in existing projects while allowing a "git init" that is run to > create a new repository by a new user who does not have any special > customization in ~/.gitconfig to use the branch name that replaces > the 'master' (I do not mind changing away from 'master', but I am > not yet convinced it should be 'main', by the way---the actual > choice of the final name does not matter at this point of the design > of backward compatibility plan). > > I think "git init" that is creating a new repository (iow, do not do > anything when reinitializing an existing repostiory) can > > - look at config.defaultBranchName in /etc/gitconfig or > ~/.gitconfig before initializing the per-repository config in > $GIT_DIR/config it just created (or it is about to create). > > - if there is no config.defaultBranchName configured, then set the > per-repository configuration to 'main' in the per-repository > configuration. Otherwise do not do anything. > > And then we make sure Don's git_default_branch_name() works this > way: > > (0) if there is config.defaultBranchName in relevant config file > (i.e. /etc/gitconfig, ~/.gitconfig or per-repo config), use the > specified name. > > (1) otherwise use 'master' (not 'main'). > > That way, an existing repository will keep using 'master' unless the > user shows the preference (and accepts responsibilities for possible > fallouts) in ~/.gitconfig or the repository's .git/config, while a > new repository created by a user who does not show any particular > preference will use 'main'. A useful addition to these 9-patch series (i.e. even before the default for vanilla usage gets changed) might be to give an example to use "git config" to grab the default branch name, e.g. name=$(git config core.defaultBranchName || echo master) Better yet (because the above forces the end users to write 'master' in their script), we might want to teach "git var" about the variable, so that the above can be written like so: name=$(git var defaultBranchName) For those not so familiar with "git var", it is a command to query "magic" variables whose value can be retrieved from different places and is backed by non-trivial logic. "What's the editor to be used?" is queried by "git var GIT_EDITOR", but that is not a simple: if test -n "$GIT_EDITOR" then echo "$GIT_EDITOR" else echo vi fi It takes the fallback `EDITOR` environment variable, and core.editor configuration variable, into account, for example. Similarly, "what is the default branch name" is not just about the value of one configuration variable. GIT_TEST_DEFAULT_BRANCH_NAME environment needs to be consulted, and when there is nothing configured, it needs to say 'master', so that end-users who use "git var" do not have to hardcode the string 'master' in their script.