✨ keith is

Rename master branch to main

2020 November 24th
2
Back to Snippets

For you

Create a new branch named main and push it to your remote.

bash
git branch -m master main
git push -u origin main

At this point, you may need to update your configuration on Github, or if you have tools that automatically deploy (Vercel, Netlify) to point to the main branch as your primary branch.

If you don't, you're likely to get an error like:

! [remote rejected] master (refusing to delete the current branch: refs/heads/master)

Then, delete the master branch:

bash
git push origin --delete master

For your team

Your team will need to do some work as well:

bash
$ git checkout master
$ git branch -m master main
$ git fetch
$ git branch --unset-upstream
$ git branch -u origin/main

This:

  • Switches you to your master branch
  • Renames it to "main"
  • Gets the latest branches
  • Removes tracking with master
  • Adds tracking with main
home