

You can opt out of this change at any time: 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 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'. How can I create a Git repository with the default branch name other than " master"? git directory when creating a repository the default (here /usr/share/git-core/templates) contains some sample hooks and other files, but you can use your new template directory to setup default hooks, for example. The whole contents of templateDir are copied to the. Using init.templateDir, you can ask git init to use a different one: # ~/.config/git/config or ~/.gitconfigĪnd in ~/.config/git/template/HEAD, put a single line (+ linebreak): ref: refs/heads/main (to default to branch main). You can, indirectly, configure git init to use a different default branch: the current branch is defined by HEAD, which is “just” a textfile telling Git which ref is the current one. You can also approach it as "creating a new branch and deleting master". This does seem a bit clunky since the mechanism is different depending on whether the repository is empty, but it works. This renames the branch from master to trunk once it's created. If you've already committed, you can run git branch -m instead: git init Instead, you can change HEAD to point at a different branch: git init -bare Bare Reposįor bare repos, you cannot run git checkout (that's what it means to be bare). git/HEAD, which explains why the master branch will disappear when you switch to trunk. Until the branch gets created, the branch only exists in. The branch master does not actually exist-the branches don't get created until they have at least one commit. This creates a new repository with trunk as the current branch instead of master. This technique works for normal (non-bare) repos: git init One option is to create the repository and then change the branch name. My Debian 10 server (Buster, the current stable version as of October 2020) comes with Git 2.20, which does not support the -b option. Some systems still have older Git installations. If I want all new repos to have "trunk" as the default branch: git config -global faultBranch trunk This is configurable with the faultBranch setting. These two commands create a new Git repo with a branch named "trunk", which always made more sense to me than "master" (master of what?): git init -initial-branch=trunk Since git version 2.28.0 the git init command now takes a -initial-branch (or -b for short) parameter.
