From Master to Main

Why Change Branch Names?

So there's a lot of things going on in the world right now, and one of those things is oppressive language. Like many other industries, there is verbiage that is currently being used in the tech industry that uses this oppressive language both casually and frequently; for instance, Git branch names.

Generally, when you are working on a project, you would use source control via a tool like Git, and save some of your most important work on a "branch". The default branch for Git is called master, and as long as you're normal, you should be able to find out why this can be considered a problem to some.

I personally don't have a problem with using a branch called master, I mean it's just a term. However, the problem isn't whether I have a problem with it, it's whether any group of people feel like it is harmful to them, especially if it is tied to something as sensitive as slavery. So out of the interest of others, and not wanting to be part of some of the oppressive systems that are still in place, I have decided that I will be using main as the default branch in all my active and future repositories.

How To Change Branch Names

Depending on the current state of your project, you will either only have a Git repo locally, or your will have your repo hosted somewhere like GitHub. Let's see how we can go from master to main in both of these states.

Without a remote repo

git checkout master
git branch -m master main
git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main

With a remote repo

git checkout master
git branch -m master main
git fetch
git branch --unset-upstream
git branch -u origin/main
git push -u origin main
git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main

Now you need to make sure you update the default branch of your repo on the hosting site.

Here's what it looks like on GitHub (Settings > Branches > Default Branch):

Update default branch on GitHub

Once the default branch has been set to main and master is no longer needed, we can delete the master branch from the repo completely.

git push origin --delete master
git branch -D master

And that's it! No we can continue working just as we did before AND be considerate of others while we do it ✊🏽