Although Git does not have an official concept of the default branch, in practice, most Git repositories have an effective default branch that serves as the primary branch for merging bug fixes and new features. It’s the first branch that appears when visiting a repository on platforms like GitHub and the branch that HEAD points to on a Git remote.
While Git itself doesn’t provide a precise definition of the default branch, its significance is widely recognized by most users. In the past, the default branch was often referred to as “master,” but recently, “main” has gained popularity as a more inclusive and diverse alternative.
In today’s guide, we’re going to show you how to change your default branch’s name through the terminal, how to set remote upstream tracking, and also how to change your default branch via GitHub.
Let’s get into it!
Change the Default Branch via Terminal
This is the first step. Crack open your terminal, navigate to your repository, and input the following code:
git branch -m master other-branch
All this command does is reset the name of your default branch from master to “other-branch.”
Put whatever name you want to use in place of other-branch. Maybe be a little more creative than me.
Setting Remote Upstream Tracking
There are still a few things to take care of here. The remote has no idea that you changed the local name. So we’ll have to fix that by setting remote upstream tracking for your new branch.
You’re going to input the following code to take care of this:
git push -u origin other-branch
You should get a message that everything is up-to-date. Now, what if you wanted to change the default branch through GitHub.com?
Changing the Default Branch on GitHub
To change your default branch, just navigate to your repository page on GitHub. Once you’re in the repo where you want to make the changes, click on settings in the upper right.
Look for branches along the left.
Then, look for the little arrows and click:
Now, if you have other branches already created, you can switch on this screen. Specify your branch and click update to make the changes.
And that’s it! It really is that simple.
If you have any questions or need any help, feel free to drop a comment below. And don’t forget to check out my other articles for more GitHub tips and coding wisdom.