How to change the default branch for new Git repositories

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.

Steps to change the default branch for new Git repositories:

  1. Set the default initial branch name for the current user.
    $ git config --global init.defaultBranch main

    Replace main with the branch name your projects use for new repositories.

  2. Confirm the saved Git configuration value.
    $ git config --global --get init.defaultBranch
    main

    If this command prints a different name, set the value again at the same --global scope.

  3. Initialize a new repository after the setting is saved.
    $ 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.

  4. Verify that the new repository starts on the chosen branch name.
    $ 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.