Renaming the Git Default Branch From Master to Main

nikki ricks
4 min readSep 16, 2021

6 Tips After Renaming Over 40 Repos From Master to Main at Work

Photo by Yancy Min on Unsplash

During my software engineering apprenticeship I had time that I could spend on side projects. One of the teams I was visiting had changed their repo default branch from master to main and I noticed that a lot of the repos at the company hadn’t updated theirs. So I put my hand up to start making the changes in other repos and here are some lessons learned and tips I thought I would pass on to others that want to update their master branch to main at their company as well.

1. Get Stakeholder Buy-In

or not? It may be likely that people at your company know about the industry changes to rename the default branch. Some may care, others may not. In any case, target the people that you may need to talk to (CTO? Architecture? Lead? Engineering Manager?) and start the conversation. Maybe something like “Hey, it looks like the wider Git community is changing the default branch frommaster to main to help make the developer environment more inclusive. It could be great if we did this too! What do you think about me taking this on in the next couple of weeks?”

But maybe you’re a ask for forgiveness, not permission kinda person. You do you.

2. Give clear context

Pointing to industry changes so people have context is great. I sourced this Github article a lot. Someone at my work created a slack channel with a post outlining the purpose for making the change, implications, potential challenges, and what’s needed to make the change. No one really interacted in the channel but it was helpful in being able to show wider company support and seeing that other teams were working on it as well.

3. Take inventory

The company I’m at is 15 years old. So there are a lot of repos that aren’t used, and forgotten about. It took some time to narrow down the list of repos to target that our department touched and had admin permission for. There were also some repos I stumbled across where the team wanted to do the change on their own timeline so it’s respecting other teams delivery priorities as well.

4. Stay true to scope

Don’t do work that’s out of scope. For example, I found when going through links to see if they have updated their repos like this one for example:

https://github.com/envato/iamy/blob/master/README.md

Github reroutes you and replaces it to main so you can do that in your codebase as well

https://github.com/envato/iamy/blob/main/README.md

But when updating hyperlinks in your codebase, you may find 404's. Updating those links, although is nice, gets into scope creep and ideally would probably be best to handle in a separate pull request (PR). The end goal is to get +1’s on the PR to not confuse busy reviewers that are context switching from other delivery work.

5. Potential complications

Some repos may be as easy as going into your Settings>Branches and making the change:

Screenshot of Github UI for renaming master branch to main

Others may have complicated CI/CD dependencies where you’ll have to time the deployment, have some pipelines fail, and need to rebuild. We use Buildkite and Heroku and needed to change the settings from master to main in those places as well. There were a lot of edge cases, so expecting repo inconsistencies is helpful!

6. Let people know

When you’re done making the change. Send a notice to all of the engineers that use that repo to run the following commands locally:

$ git branch -m OLD-BRANCH-NAME NEW-BRANCH-NAME
$ git fetch origin
$ git branch -u origin/NEW-BRANCH-NAME NEW-BRANCH-NAME
$ git remote set-head origin -a

These commands will also show up on your Github repo main page when you’ve changed the settings. Like this:

Screenshot of the Github UI modal when you change the default master branch to main on the main page of the repo. A modal appears under the main branch dropdown.
Screenshot of Github UI modal of the main branch change notification

Now celebrate! Although some may think this change is performative. I would rather error on the side of performance than exclusion (or white supremacy). For me, this type of work is ideal as it overlaps a bit of activism (although corporate) while still being technical. All the best!

I’m currently looking for work! I’m a Junior Engineer with 1.5 years of experience. Checkout my LinkedIn post to see what I’m up to and the type of work I’m interested in. Would love to connect. :)

--

--