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.
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.
Step 3: On the branches screen you would find a small edit button, just click on it.
Step 4: Update the new name you want in the field box.
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.
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:
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:
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.
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:
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:
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.
1 Response
[…] Make sure you check out our renaming origin branch tutorial as well for Git. […]