Configure git to use 'main' as the primary branch


Historically, when a new git repository was created, the primary branch was named master. Many companies that use the git software such as,, and have renamed this primary branch to main. The following links give you more information about this topic:

What does this mean?

If you created a repository on your DreamHost server in the past, the primary branch is named master. This will continue to function normally on your DreamHost server without any issue.

However, it's recommended that going forward, you create new repositories with the primary branch name of main. This will ensure future compatibility with other software programs as mentioned above.

Updating your git config file

You can run the following command to add a line to your git config file. This will ensure all future repositories you create use main as the primary branch.

The following steps can be run on your local computer or your DreamHost server.

  1. Open a terminal on your home computer or log into your DreamHost server via SSH.
  2. Run the following command:
    [server]$ git config --global init.defaultBranch main

Now when you initialize a new repository by running git init, main will be used instead of master as the primary branch.

Changing an existing repository to use main

If you've created a repository in the past using git, the primary branch is named master. You can check by running the following command on your home computer or DreamHost server.

[server]$ git branch -a

If there are multiple branches, the active branch will display a * to the left. If you see the primary branch is master, run the following commands to update it to main.

  1. Make sure the active branch is master.
    [server]$ git checkout master
  2. Rename it using the -m option.
    [server]$ git branch -m main

    If the main branch exists for some reason, you can use -M to force the rename.

Updating remote repositories

If you have pushed this local repository to a remote repository (such as, you must push it again to reset the upstream branch.

Change REMOTENAME to the name of your remote repository. Run git remote to view existing remotes.

[server]$ git push -u REMOTENAME main

You should then delete the old master branch.

[server]$ git push REMOTEBRANCH --delete master

View the following link for further details.

See also

Did this article answer your questions?

Article last updated PST.

Still not finding what you're looking for?