Skip to content

Instantly share code, notes, and snippets.

@theintz
Created January 14, 2021 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theintz/1fca257055294101691c0d7cca2540a1 to your computer and use it in GitHub Desktop.
Save theintz/1fca257055294101691c0d7cca2540a1 to your computer and use it in GitHub Desktop.
Renaming git branches: master -> main

Instructions for repo maintainer

  1. Create main branch off of up-to-date master: git checkout master && git pull && git checkout -b main
  2. Push main to origin and set-up tracking: git push -u origin main
  3. Set main as default branch and adjust branch protections in Gitlab/Github settings
  4. Instruct your fellow developers who have local clones of the repo to follow the steps below. Once everyone is done updating:
  5. Delete master branch in Gitlab/Github

Instructions for repo users

  1. Make sure code tree is clean, ie. all changes are committed or stashed away. Also ensure that your local master branch is identical to the remote one.
  2. Update local git repo:
git checkout -t origin/main
git remote set-head origin -a && git remote prune origin
git branch -d master

Running git branch should now only display main among your local branches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment