Skip to content

Instantly share code, notes, and snippets.

@deild
Last active January 2, 2021 15:33
Show Gist options
  • Select an option

  • Save deild/460aa05657cc3ec18a992174bb835128 to your computer and use it in GitHub Desktop.

Select an option

Save deild/460aa05657cc3ec18a992174bb835128 to your computer and use it in GitHub Desktop.
5 steps to change GitHub default branch from master to main

All commands

# Step 1 
# create main branch locally, taking the history from master
git branch -m master main

# Step 2 
# remove the "upstream" branch link to origin/master
git branch --unset-upstream

# Step 3
# push the new local main branch to the remote repo (GitHub) 
git push -u origin main
git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main

# Step 4
# change the default branch on GitHub to main
# https://docs.github.com/en/github/administering-a-repository/setting-the-default-branch
# retarget existing PRs
# https://github.com/ethomson/retarget_prs

# Step 5
# delete the master branch on the remote
git push origin :master

Easily rename your Git default branch from master to main by Scott Hanselman

Git: Renaming the “master” branch by Richard Walters

How To: Safely Rename master Branch on GitHub by Jake Jarvis

How to Rename Your Master Branch to Main in Git by Eric Lu

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