Git names the first branch of a new repository from its initial-branch setting. Setting that value before running git init keeps new local projects on the branch name used by the rest of the team, such as main, without renaming each repository after it is created.
The persistent setting is init.defaultBranch. A global value affects new repositories created by the current user, while existing repositories keep their current branch names until they are renamed or migrated separately.
The commands below were verified in an isolated Ubuntu 26.04 container with the distribution Git package. Use a branch name that is valid for the projects being created, and coordinate separately before changing the default branch of a shared remote repository because hosting platforms, open pull requests, and automation may also need updates.
Related: Create a local Git repository
Related: Rename a Git branch
Related: Run a default branch rename in Git
$ git config --global init.defaultBranch main
Replace main with the branch name your projects use for new repositories.
$ git config --global --get init.defaultBranch main
If this command prints a different name, set the value again at the same --global scope.
$ mkdir project $ cd project $ git init Initialized empty Git repository in /home/user/project/.git/
init.defaultBranch affects repositories created after the setting is changed. It does not rename branches in repositories that already exist.
$ git status -sb ## No commits yet on main
Before the first commit, Git still reports the unborn branch name in status output. After the first commit, new commits are recorded on that branch.