Skip to main content

How to rename the ‘master’ branch on GitHub

First posted in Development and Git; updated 26th February 2021

So renaming master to main is a good idea, but how do we do it? It’s really easy if you’re using GitHub:

  1. Go to your repository (repo) and find the ‘Branches’ link (including a wee branch icon and the number of existing branches), or navigate to
  2. In the ‘Your branches’ section, hit the pencil icon on the master line
  3. In the ‘Rename this branch’ dialog, get rid of the word master, type main, and press ‘Rename branch’

That updates the branch name centrally; next we need to update the branch name on all of the machines that connect to this repo, run three commands:

git branch -m master main
git fetch origin
git branch -u origin/main main

You can just blindly copy and paste that code block to run all three, but let’s break down what each line is doing:

  1. First we rename the local branch from master to main, to match what we’ve just done on the remote repo: git branch -m master main
  2. Next, we get the most up to date info from the remote repo (in other words, the fact that master is gone and there’s a ‘new’ main branch): git fetch origin
  3. Lastly, we set the ‘upstream’ branch to main for your local main branch, so that pushing and pulling without specifying the branch is possible git branch -u origin/main main

Don’t forget that anything you’ve got that watches for changes to your master branch, like Netlify build hooks, will need to be updated to watch main instead.


If you enjoyed reading this and want a monthly roundup of my articles delivered to your inbox, just enter your email below.

I don’t collect any data on when, where or if people open the emails I send them. Your email will only be used to send you newsletters and will never be passed on. You can unsubscribe at any time.

More posts

Here are a couple more posts for you to enjoy. If that’s not enough, have a look at the full list.

  1. An update on Google and the open web

    A year ago, I wrote about how Google were spoiling my Blue Beanie Day. Since then, there have been some changes; some positive, others not so much.

  2. What do we do with a link or button matters

    Language is a powerful thing; if the metaphor we use to describe actions to our users is ‘click’ we tend to forget about all those who don’t.