Skip to main content

GIT - rename a local and remote branch

First checkout to your old branch:

git checkout old_branch

To be sure that you have a branch up to date:

git pull origin old_branch

Rename local branch:

git branch -m old_branch new_branch

Set upstream to track your new named branch:

git push -u origin new_branch

Remove old remote branch:

git push origin :old_branch

More details

-m option is clearly explained in GIT documentation:

With a -m or -M option, <oldbranch> will be renamed to <newbranch>. If <oldbranch> had a corresponding reflog, it is renamed to match <newbranch>, and a reflog entry is created to remember the branch renaming. If <newbranch> exists, -M must be used to force the rename to happen.

You can also use -c option to copy your branch instead of renaming.

Add new comment


This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

We use cookies on our website to enhance your user experience. We also use Google analytics and ads.

Click here to read more I've read it