Change your local default git branch


GitHub announced that it will be retiring certain terms from its platform. This includes the use of master to refer to default branches.

Want to change all of those current projects that you have to use a different default branch? Fortunately, git makes the process of changing default branches very easy.


Let's say that you want to use main as your new default branch.

In your project directory, do the following:

git branch -m master main
git push -u origin main

The first command will create a branch called main and copy master to it. This means that your git log is preserved in its entirety. The second command pushes the main branch to your designated remote, whether it be GitHub, GitLab, Sourcehut, local git server, etc.

That is it!