DEV Community

Cover image for From 'master' to 'main': The easy guide to renaming your Git default branch for a more inclusive codebase
Ackshaey Singh
Ackshaey Singh

Posted on

From 'master' to 'main': The easy guide to renaming your Git default branch for a more inclusive codebase

I started heavy development on Firecode.io this week to get it out of beta - and one of the first changes I had to make was renaming my primary branch to "main". In 2020, Github announced that it would be dropping the use of the term "master" for the default branch name on its platform. This decision was made in response to calls for more inclusive language in tech, as "master" has historical connotations of slavery and domination. The change has been supported by many in the tech industry who recognize the importance of taking small but significant steps towards creating more inclusive spaces for everyone.

Since Github is one of the most popular code hosting platforms, this change has had a ripple effect across the tech industry. Many companies and organizations have followed suit and made the switch from "master" to "main" for their default branch names. This has involved going through a series of steps to rename the branch, update links, and make sure that the change is reflected in all relevant places.

Making this change is actually quite simple and should only take a couple of minutes:

Step 1: Create a new branch

The first step is to create a new branch called main from the existing master branch.

git branch -m master main
Enter fullscreen mode Exit fullscreen mode

This command renames the master branch to main.

Step 2: Push the new branch to the remote repository

Next, you need to push the new main branch to the remote repository:

git push -u origin main
Enter fullscreen mode Exit fullscreen mode

This command pushes the new main branch to the remote repository and sets up tracking so that future git push and git pull commands work as expected.

Step 3: Point the HEAD to the new branch

The next step is to point the HEAD to the main branch. You can do this using the following command:

git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main
Enter fullscreen mode Exit fullscreen mode

This command is used to update the HEAD reference in the Git repository to point to the new default branch "main" after renaming the "master" branch. In Git, the HEAD reference points to the current branch or commit that is being worked on. By default, the HEAD reference points to the current branch, which is usually the default branch. In this case, since we renamed the default branch from "master" to "main", we need to update the HEAD reference to point to the new default branch "main". The first argument is refs/remotes/origin/HEAD, which is the remote tracking branch reference that corresponds to the default branch on the remote repository. The second argument is refs/remotes/origin/main, which is the new default branch name we want to set the reference to.

Step 4: Change the default branch on the Github

Now that you've created and pushed the new main branch, you need to change the default branch on the Github (or BitBucket or wherever you host your repo). Depending on where you host your repo, this should be a simple change from the web UI.

Step 5: Delete the old branch

Finally, you can delete the old master branch:

git push origin --delete master
Enter fullscreen mode Exit fullscreen mode

And that's it! You've successfully renamed the default branch of your Git repository from master to main.

It's worth noting that this change may affect some build systems or scripts that rely on the master branch name, so you may need to update them accordingly. Additionally, if you're using other Git-based tools, you may need to update them to work with the new main branch. In my case, I had to rename all my terminal aliases and update multiple cloud build scripts to pull the right code.

The shift towards more inclusive language in tech is an important one, and every small step taken towards creating more welcoming and equitable spaces is a step in the right direction.


Preparing for a coding interview? Check out Firecode.io

Top comments (5)

Collapse
 
jonrandy profile image
Jon Randy ๐ŸŽ–๏ธ • Edited

This again... it was bizarre then, and bizarre now. This was one of the best responses I saw to the 'controversy' at the time...

master branch

Context is everything.

Collapse
 
jmfayard profile image
Jean-Michel ๐Ÿ•ต๐Ÿปโ€โ™‚๏ธ Fayard • Edited

It's not a big deal but language reflects the values of societies it evolved in, so it makes sense to refactor it from time to time.

The nazi flavor of German is an interesting illustration of that:
See LTI โ€“ Lingua Tertii Imperii

Part of the confusion in that particular case is that many people thought that master had some kind special meaning in git, while in fact absolutely not, it's a label like any other apart that it was (but not always anymore) there by default.

Collapse
 
ackshaey profile image
Ackshaey Singh

TIL LTI! I think that's a really healthy take on it, it's human nature to resist change, and like you said it makes sense to refactor language from time to time.

Collapse
 
ackshaey profile image
Ackshaey Singh • Edited

@jonrandy I can appreciate that this is bizarre for you, and this reply isn't intended to change your mind on the issue. I believe in free speech and not compelling speech of any kind. But since you included the response from Sam Parker, let me respond to his take with my perspective on this:

a) Terms such as "master" and "master-slave" have been used in many contexts, in many cultures around the world. The African American experience is but one of them. I'm not black and I'm not white - I am a South Asian of Indian origin. Being of a certain race or nationality doesn't give me the right to paint the experience of a race with a broad brush, but playing the same card as Sam above, I associate the term "master" with Indian enslavement by the British more than I do with the history of slavery in the US. The point is, the African American experience is one of many experiences associated with slavery and servitude around the world.

b) The entire concept of inclusivity is centered around us getting through our day to day activities without unnecessarily reminding historically oppressed people of their past oppression, which is still alive and well in many parts of the world. If it means renaming a "master" branch to "main" or using "primary-replica" instead of "master-slave", it's a small change for me to not take a stand against.

c) Lastly I don't agree with his claim that people who think we should move away from this terminology in tech are bullies or racists, that's not backed by any facts or data and sounds more like projection than anything else.

I'm hoping this sheds more light on why this is relevant for others reading this thread.

Collapse
 
esra577 profile image
Esra Mohamed

when I try to implement step two I get error : failed to push some refs to 'origin'