For a long time Git has used the default branch name of master. Recently, they decided that it would be best to change the default name from master to main. All new versions of Git come with the default branch name now set to main.
Git – Renaming the default branch from master
But what about your projects?
If you are developing your own systems, or you have an abstract fear of the word ‘main’, you can still change the default branch name for your Git repositories to something that makes sense to your process. For example, you might want to set the default name to release, or production. Or maybe you could set it to your company name, or your pet’s name, as long as you don’t use it as a security question.
Is it easy to change the default branch name in Git?
It’s like changing a lightbulb. It only takes a single line of code in a terminal, and another one to check that the change has been made.
If Git is not installed, the following article from the official Git page can guide you through installing Git on your computer. Getting started – Installing Git
To change the default branch name:
- Open up your terminal.
- In Windows, press Windows key + R. Then in the window that appears, type in
cmd
and press enter. - In Mac, bring up the Spotlight search by pressing Command + Space, then type in
terminal
to search for and open the terminal application.
- In Windows, press Windows key + R. Then in the window that appears, type in
- In the terminal window, check the version of Git on your computer. This will also let you know if it is installed on your system
- In the terminal, type in the command
git --version
- In the terminal, type in the command
- Next, get the current settings for Git on your computer
- Type in
git config --list
- Type in
- You should see a setting called init.defaultBranch. If the value is not set to main, you can use the following command to change the default branch name to main
- Type in
git config --global init.defaultBranch main
- Follow it up by running the
git config --list
command again - The value of init.defaultBranch should now be main
- Type in
If that is a little bit confusing, that’s ok. Sometimes it’s easier to see it visually. Please watch the following YouTube video which shows how to change the default branch name in Git.
That’s all you need to do. A single line of code to change the default branch name in Git. Like changing a light bulb.