How To Rename Local and Remote Git Branch

0

ADVERTISEMENT

This tutorial will help you to rename local and remote git branch and fix the branch that was named incorrectly and not followed the naming convention of your organization.

Git allows you to rename the branch easily using the -m option.

Rename Local and Remote Git Branch

Unfortunately, you can’t directory rename a remote git branch. To achieve this, we need to delete the old remote git branch and then push the renamed local branch.

Please follow the steps.

1. Rename Local Git Branch

Use -m option with git command to rename the local git branch to your desired name. This command will rename the currently active git checkout <old_branch_name> branch.

git branch -m <new_branch_name>

2. Delete Old Remote Git Branch

As i said earlier, to rename the remote git branch, you need to delete remote git branch first.

git push origin --delete <old_branch_name)

3. Push New Git Branch

Push the new local branch <new_branch_name> to the remote and reset the upstream branch.

git push origin -u new_branch_name

Conclusion

You have successfully renamed you local and remote Git branch. Renaming a branch whether it is local or remote, it is very easy. Share your feedback in the comments section.

You might also like