How to Rename Git Local and Remote Branch on Ubuntu

This brief tutorial shows students and new users how to rename Git local and remote branch on Ubuntu 18.04 | 16.04

This should help in cases where you create a git branch and publish to the remote repository but realize its an incorrect naming convention or name for the branch…

You can use the steps below to rename the published branch to a new format or name… You can’t just rename git branch in the repository… you must checkout, the rename the branch, then push the new name and delete the old..

You can use git renaming feature to rename a branch and push to the remote repository easily using the git branch -m command

When you’re ready to rename git local and remote branch, follow the steps below:

Step 1: Switch to old branch

First step is to switch to the old branch you want to rename.. you can do that by using the command below

git checkout old_branch_name

Replacing old_branch_name with the current branch you want to rename…

Step 2: Rename the branch

Now that you have checkout the branch you want to rename, simply run the commands below to rename it…

git branch -m new_branch_name

Replacing new_branch_name with the new branch you want to public

The steps above renames a git branch

Step 3: Delete old branch and push new branch

Step 1 and 2 shows you how to rename a local branch… However, if you have already published an incorrect git branch to the remote repository, simply run the commands below to delete the incorrect name…

git push origin --delete old_branch_name

Then public the new name using the commands below

git push origin -u new_branch_name

This is how you rename a local branch and remote branch using git branch -m command

Conclusion:

You have successfully learned how to rename git local and remote branch.. With git, you can just rename a branch already on the remote repository.. you will have to delete the old and publish the new one..

You may also like the post below:

Revoking Let’s Encrypt Certificates on Ubuntu 18.04 | 16.04

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.