Skip to content

Renaming master branches to main

Devon Carew edited this page Jan 23, 2023 · 5 revisions

Many of our repos currently use master as the name of the default branch; over time we'd like to have them instead use main as the name of the default branch.

The work per-repo is fairly modest. For people who want to take this on for a repo, here are the steps:

  • pre-announce the move (as a GitHub issue or as a communication to the active user group)
  • use the rename branch feature to rename master to main; this is available from the <org>/<repo>/branches page. If you do not have rights to rename the master branch, ping @devoncarew or @athomas
  • update references to the old branch name (generally in the workflow files in .github/workflows)
  • for google3, in third_party/dart/<packageName>/copy.bara.sky, update the name of the branch that we sync to (branch = "main")
  • message to users that the change was made and how to update any local checkouts

GitHub's doc for this are here: renaming a branch. After the rename, people with local checkouts will need to run:

git branch -m master main
git fetch origin
git branch -u origin/main main
git remote set-head origin -a

The GitHub UI will prompt them to do that the next time they visit the repo page.

Clone this wiki locally