Browse Category

Version Control

Git rename local and remote branches

I have created a new branch which was mainly to test some new functions written in other programming language several weeks ago.

Because the branch was for developing purpose, I didn’t put much effort in naming it.

In recent days, I was reviewing the repository and found that the name of that branch didn’t quite fit its purpose.

So I googled a bit how to rename local branches and remote branches.


Renaming Local Branches

git branch -m {the branch intended to rename} {new branch name}

This command should rename a local branch.

After that, we should push our modification to the server and remove the branch with old name from the server.

git push origin {new branch name} :{the branch to remove}


Rename Remote Branches

If the branch we would like to rename doesn’t exist in our computer but on the server, we should duplicate it and give the copy a desired name.

git branch {new branch name} origin/{the branch intended to rename}

Push our modification to the server. And the new branch with the desired name should appear in the repository.

git push origin {new branch name}

Since the old branch is redundant, remove it from the server.

git push origin :{the branch to remove}


Well done. The branches are renamed into the desire names.