How to Rename your Origin Branch in GitHub

While working on GitHub, you can change the name of the branches by using the Settings section. This tutorial will focus on how to rename your origin branch in GitHub.

The good part about Git is that it is very self-explanatory. They guide you through every step, letting you understand what is what. If you still get confused a little bit you can always check this tutorial.

meme for git merge

So we are seeing how to rename your origin branch in GitHub and Setting This is how to do it.

Steps on How to Rename your Origin Branch Name in GitHub

As you can see my master branch name is jestBranch. I was working on Jest that’s why. I want to change this branch to be called master.

Step 1: Click on Settings as shown in the image below.

Step 2: When you navigate to the Settings page, on the left side pane click on Branches.

Branches option on How to Rename your Origin Branch in GitHub

Step 3: On the branches screen you would find a small edit button, just click on it.

the edit button option for How to Rename your Origin Branch in Github

Step 4: Update the new name you want in the field box.

How to Rename your Origin Branch in GitHub prior to final change

Step 5: I want my branch to be called master. So I have updated it here. Notice how the green checkmark on the right tries to validate this name. Once you are done, click on Rename Branch button.

How to Rename your Origin Branch in GitHub screenshot for master

Step 6: The next screen will reflect the change you made. That’s it, you are done.

How to Update Your Local Clone to Reflect Above Changes

If you click on your repo name, and navigate back to where you initially were, you will notice the change is explained like this:

local clone suggestion Default branch name

Also, as you can see it’s good advice that is flared in front of you.

Step 1: Now in order to make sure that your local clone knows about this change. You have to first rename the branch to master using the following command:

git branch -m jestBranch master

Here master is the name I chose for my origin branch.

So from the Git bash terminal, I am going to rename my local branch:

git bash terminal screenshot 1st step

Step 2: Then type the following command to basically pull the origin branch:

git fetch origin

This is how it would appear on git bash terminal.

git bash terminal screenshot 2nd step

Step 3: Next, you gotta set your branch to track remote branch. You do so by typing the following:

git branch -u origin/master master

Here’s how it would appear on git bash terminal:

git bash terminal screenshot 3rd step

Step 4: Once that is done you set the head to origin by using the following command:

git remote set-head origin -a

The above command will set the origin head to your renamed branch

Here’s a git bash terminal screenshot:

git bash terminal screenshot final

You are done. Now when you commit changes and push to origin, it will go to your origin which is master now (here) or whatever name you chose.

If you like this tutorial, please check out other tutorials on Git on our website.

Scottshak

Poet. Author. Blogger. Screenwriter. Director. Editor. Software Engineer. Author of "Songs of a Ruin" and proud owner of four websites and two production houses. Also, one of the geekiest Test Automation Engineers based in Ahmedabad.

You may also like...

1 Response

  1. September 27, 2021

    […] Make sure you check out our renaming origin branch tutorial as well for Git. […]

Leave a Reply