DEV Community

Cover image for Rename the master branch on GitHub web, without command line Git
Aalaap Ghag
Aalaap Ghag

Posted on

Rename the master branch on GitHub web, without command line Git

Most of the guides to renaming the master branch to main (or whatever you choose) resort to asking you to to use the command line Git app to check out the repo, make the change and push it back up. That's fine if you're on your development machine with SSH keys added and everything set up, but what if you need to do this from a temporary workstation with no SSH keys or perhaps no Git even? What if you wish to do so using a portable device like your smartphone or an iPad?

I have a lot of repositories on GitHub, both public and private. Some of these are past projects that I don't have a local working copy of, so checking out and going through all those steps seems like a tedious task.

Thankfully, there is an easier way using the GitHub web interface that involves none of this. From the GitHub repo that you wish to do this for...

  1. Click on the branch button again and type in a name for the new branch, eg main. Ensure you're doing this while on the master branch.
  2. Click on the branch button once more and then on View all branches.
  3. In the list of branches that shows up, next to your master branch, click on the button to Change default branch.
  4. From the dropdown that shows up, pick the name of your new branch and click Update.
  5. Read the warning and click I understand, update the default branch.

You're done at this point, but you can and should also go and delete the master branch.

  1. Click on the Code tab to return to the code.
  2. Click on the branch button and View all branches again.
  3. Click on the red trash can icon next to the master branch.

That's all it takes!

Thank you for making the world a better place. Stay safe and keep coding!

Discussion (0)