lots of tech info here

How to Rename Local and Remote Git Branch

Published on 01 April 2020 | No Comments

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. 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.

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.

  1. Rename the local branch:
git checkout feature
git branch -m assortment
  1. 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.

  1. Delete the old name remote branch feature:
git push origin --delete feature

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

You can verify all branches with:

git branch -a

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

Created on 01 April 2020

TAGS: git

If you liked this article, follow us on Facebook and Twitter (@aruljohn).

Share this with Others

Subscribe

Tags