How to Rename Git Local and Remote Branch on Ubuntu

This tutorial guides on how to rename Git local and remote branches on Ubuntu 18.04 | 16.04. The process involves checking out the branch to be renamed, renaming the branch, and pushing the new name while deleting the old one. This can all be done using the ‘git branch -m’ command.

This brief tutorial shows students and new users how to rename Git local and remote branches 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 it’s 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 the git branch in the repository. You must check out, rename the branch, then push the new name and delete the old one.

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

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

Switch to the old branch

The 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

You are replacing old_branch_name with the current branch you want to rename.

Rename the branch

Now that you have checked 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 rename a git branch

Delete the old branch and push a new branch

Steps 1 and 2 show 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

The public the new name using the commands below

git push origin -u new_branch_name

This is how you rename local and remote branches using the git branch -m command.

Conclusion:

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

You may also like the post below:

Richard Avatar

Comments

Leave a Reply

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


Exit mobile version