Tutorials

How To Rename A Local And Remote Git Branch | Git Guides

How To Rename A Local And Remote Git Branch | Git Guides
Written by itsubuntu

How To Rename A Local And Remote Git Branch | Git Guides

If you looking for a tutorial to rename a local and remote git branch then you are in the right place as you can see the step by step tutorial to rename a local and remote git branch.

How To Rename A Local And Remote Git Branch | Git Guides

At first, let’s start by renaming a local git branch.

How To Rename A Local Git Branch

At first, you need to select a brand that you want to rename and switch to it.

git checkout old-git-branch-name

Using the Git rename branch command, you can easily rename a local git branch.

git branch -m new-git-branch-name

Meanwhile, if you want to rename a local branch without switching to it then run the following command:

git checkout master
git branch -m old-git-branch-name new-git-branch-name

You can verify the changes by running the following command:

git branch -a

Now, let’s move on to the process to rename the remote git branch.

How to Rename a Remote Git Branch?

At first, you need to rename a local branch. You can follow the previous steps where we renamed a local git branch.

Now you need to delete the old branch and push the new one.

git push origin :old-git-branch-name new-git-branch-name

After executing the above method you need to reset the upstream branch for your new local branch

git push origin -u new-name

You have successfully renamed the local and remote Git branch.

About the author

itsubuntu

Leave a Comment