Change GitHub default branch from master to main

Change GitHub default branch from master to main

Step 1

Create main branch locally, taking the history from master

git branch -m master main

Step 2

Push the new local main branch to the remote repo (GitHub)

git push -u origin main

Step 3

Switch the current HEAD to the main branch

git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main

Step 4

Change the default branch on GitHub to main

At this point you’ve succesfully transitioned everything to the ‘main’ branch, but you can’t delete the ‘master’ branch without changing the default branch in GitHub to something other than ‘master’. For this:

  • Navigate to your github repository
  • click "Settings" -> "Branches" on the sidebar
  • Change the default branch to ‘main’.

For detail instruction check setting the default branch on github

Step 5

Delete the master branch on the remote

git push origin --delete master