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 https://github.com/myUserName/myRepoName/branches
  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.

Accessibility in your inbox

I send an accessibility-centric newsletter on the last day of every month, containing:

  • A roundup of the articles I’ve posted
  • A hot pick from my archives
  • Some interesting posts from around the web

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. Alt text for CSS generated content

    There’s an interesting feature in Safari 17.4 that allows content added with CSS to have ‘alt’ text. I’m not sure how I feel about this.

  2. The accessibility conversations you want to be having

    In most companies, accessibility conversations centre around WCAG compliance, but that’s just the start. Thinking beyond that is where you want to be!