Skip to content

Instantly share code, notes, and snippets.

@arichar6
Last active July 10, 2020 16:07
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 arichar6/357c0254c7d84603ce7256f2a74f8a22 to your computer and use it in GitHub Desktop.
Save arichar6/357c0254c7d84603ce7256f2a74f8a22 to your computer and use it in GitHub Desktop.
These commands should let you rename the default branch in a git repo
# On your local clone, make sure that your code is up to date with the remote (called `origin`)
git pull origin master
# Then rename your local `master` branch to `main`
git branch -m master main
# Then push your `main` branch back to `origin`, using a command that will make a new branch called `main` on the remote.
git push origin HEAD
# After this, you can:
# - Edit any existing pull requests to point to `main` instead of `master`
# - Change the "default" branch to be `main` (this applies to GitHub and GitLab remotes)
# - Delete the `master` branch if desired (or leave it, in case you run into problems)
# You can also repeat the above commands for other remotes, if applicable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment