Overview
When you initialize a new git repository via SSH on a DreamHost server, the primary branch is named master. This is because the git software currently defaults to this branch name.
Many companies that use the git software as the basis of their platforms, such as github.com, gitlab.com, and bitbucket.org, have renamed this primary branch to main. The following links give you more information about this topic:
- git-scm.com/book/en/v2/Git-Branching-Branch-Management
- github.com/github/renaming
- sfconservancy.org/news/2020/jun/23/gitbranchname/
- about.gitlab.com/blog/2021/03/10/new-git-default-branch-name/
- bitbucket.org/blog/moving-away-from-master-as-the-default-name-for-branches-in-git
What does this mean?
When you create a repository on your DreamHost server, 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 rename the primary branch name to main for your repositories. This will ensure future compatibility with other software programs, as mentioned above.
Changing the primary branch to use 'main'
Newly created repositories use the name master as the primary branch. To ensure future compatibility, it's recommended you now update this branch name to main.
- Check the name of your branch 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.
- Make sure the active branch is master.
[server]$ git checkout master
- 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.
- Update symbolic refs to use main.
[server]$ git symbolic-ref HEAD refs/heads/main
Updating remote repositories
If you have pushed this local repository to a remote repository (such as github.com), 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.
Updating your git config file (on your home computer)
The following command only works with git versions 2.28 or higher. DreamHost servers run the git version installed with the server's Operating System, which is currently below version 2.28. To confirm, log into your server via SSH and run the following command:
[server]$ git --version
If the version is below 2.28, you must use the option above to manually rename the branch.
If the version of git on your home computer is above 2.28, you can run the following command to add a line to your git config file. This will ensure all future repositories you create (on your home computer) use main as the primary branch. You can then push them to your DreamHost server using the instructions in the following articles:
- Pushing your local Git repository to a DreamHost server — Linux & Mac OS X
- Pushing your local Git repository to a DreamHost server — Windows
Running the command
- Open a terminal on your home computer.
- 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.