Skip to content

Instantly share code, notes, and snippets.

@dominique-mueller
Last active April 13, 2021 16:45
Show Gist options
  • Save dominique-mueller/5ed5a4c3d71f2427cf0ccfdcb39d667c to your computer and use it in GitHub Desktop.
Save dominique-mueller/5ed5a4c3d71f2427cf0ccfdcb39d667c to your computer and use it in GitHub Desktop.
Make the switch from master to main, quick and easy.

Migration of remote

In your cloned repository:

  1. Switch to "master" branch:
    git checkout master
  2. Rename the "master" branch to "main" by running:
    git branch -m master main
  3. Push new "main" branch to remote by running:
    git push -u origin main
  4. If "master" was the default branch (often develop acts as the default branch): In the GitHub project settings, change the default branch from "master" to "main"
  5. Cleanup old "master" branch by running:
    git push origin --delete master

Note: You might change your protected branches


Migration for cloned repositories

Other people then either re-clone the repository from scratch or:

  1. Switch to the "master" branch by running:
    git checkout master
  2. Rename the "master" branch to "main" by running:
    git branch -m master main
  3. Fetch latest from remote by running:
    git fetch
  4. Remove tracking of remote "master" branch by running:
    git branch --unset-upstream
  5. Add tracking of remove "main" branch by running:
    git branch -u origin/main

Notes

Make sure to:

  • Update CI / CD pipelines to work with new main branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment