DEV Community

Sam Wight
Sam Wight

Posted on

How to rename your main Git branch to main

I've been seeing a lot of talk lately about renaming the default GitHub branch to main. I think this is a really good idea! Something simple that promotes inclusion is always something that I will support. Thankfully, Git branches are built to make changes like this extremely easy. In this (very short) post, I'll show you how to rename your main Git branch to main, and how to update the default branch on GitHub. Overall, this should take you about five minutes total. Just five minutes!

The commands

First, here's the commands to change your default branch name to main:

git branch -m old_branch_name main
git push --set-upstream origin main

The first command renames old_branch_name (your default branch name here, whatever that may be) to main. The next branch pushes that new main branch to the remote. Replace origin with whatever remote you use for your main repo host. Once you run these commands, you'll have your brand new main branch. Isn't that cool!

Updating GitHub

If you're using GitHub like I am, then updating your default branch is a little bit more involved. First, navigate to Your RepoSettingsBranches. There, you should be able to change the default branch to main.

If you don't want to keep the old branch name around, you can easily delete it (after all, it was easy enough to create!). Navigate to the root of your repo and click on the branches icon (the one with the number of branches your repo has). You should then be able to delete your old branch name.

Congrats, you've now renamed your default branch to main!

Latest comments (1)

Collapse
 
waylonwalker profile image
Waylon Walker

👏 I have started renaming my master branches as well. I think anything that makes a project more welcoming is a good thing. Honestly its so simple to do, I really don't understand the uproar. I went ahead and renamed master in all of my blog posts and routes as well as the repo itself.