How to Rename Local and Remote Git Branch

Published December 29, 2024

How to rename local and remote git branches How to rename local and remote git branches

If you are developing a software project along with many other team members and use a git repository, you will most likely be using branches. This tutorial shows you how to rename your local and remote git branches.

You have an existing feature branch that you pushed to remote

Let's assume the name of your branch is feature. Your steps to check in your code would be something like this:

git checkout feature
git add .
git commit -am 'Added xyz'
git push -u origin feature

Your local branch feature is now pushed to remote branch.

Let us rename the remote branch

You get a request to rename the branch to assortment.

If you hadn't pushed the branch to remote, this would have been the solution:

git branch -m assortment

However, since the branch has been pushed to remote, we need to do a few extra steps.

Rename the local branch

git checkout feature
git branch -m assortment

Push the newly named local branch assortment and reset the upstream

git push -u origin assortment

If the above command doesn't work, you can edit the file .git/config and replace the remote upstream name feature with the local branch name assortment.

Delete the old name remote branch feature

git push origin --delete feature

This would effectively rename the remote branch to the new name.

Verify the branch

You can verify all branches with:

git branch -a

and you should be able to see the local and remote assortment branches.

Related Posts

If you have any questions, please contact me at arulbOsutkNiqlzziyties@gNqmaizl.bkcom. You can also post questions in our Facebook group. Thank you.

Disclaimer: Our website is supported by our users. We sometimes earn affiliate links when you click through the affiliate links on our website.

Last Updated: December 29, 2024.     This post was originally written on April 01, 2020.