Skip to content

Instantly share code, notes, and snippets.

@annawinkler
Last active March 15, 2021 23:54
Show Gist options
  • Save annawinkler/713af448dda72c62ae547408f40ccd68 to your computer and use it in GitHub Desktop.
Save annawinkler/713af448dda72c62ae547408f40ccd68 to your computer and use it in GitHub Desktop.
Change your default branch to main in git

It's easy to change your default branch to main!

On the command line, in the directory for your repository, run these commands to make sure you have all of the changes pulled down to master, move master to main, and push the new main branch:

git checkout master
git pull
git branch -m master main
git push -u origin main

Then in your repository:

  1. As an admin, click Settings, then Branches, and then change the default branch by selecting Switch to another branch.
  2. Are any PRs open that use the old, default branch? If so, edit them and change the target branch to main.
  3. Are there any branch protection rules? Change them to target main.
  4. Delete the old, default branch to avoid confusion.

Let your developers know:

  • On your local laptop, pull the new branch via git fetch
  • Then check out main: git checkout main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment