Replace master with main branch on Github

Here are the steps to replace master with main branch.

This is a simple fix to avoid any negative connotations inherit in master:slave terminology. Although in the history of git the etymology of master was in the sense as master:copy.

Move the master branch to main with the command:

git branch -m master main

Using the argument -m will transfer all of the commit history on the ‘master’ branch to your new ‘main’ branch so nothing gets lost. Push the newly-named main branch to GitHub (assuming that is your remote repository) with the command:

git push -u origin main

Point HEAD to main with the command:

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

Now you need to set "main" as the default branch for your project on GitHub. To do that, log in to your GitHub account, open the repository for the project, and click Settings | Branches. In the left sidebar, click Branches and then select Main as your default from the drop-down. Click Update and, when prompted, click I Understand. Now, back at the terminal issue the command:

git push origin --delete master

That's it!

Sources: Github, Techcrunch, 9/22/2020

Tagged with

← Previous Listen First We are lost Next →