DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,673 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Teerasak Vichadee
Teerasak Vichadee

Posted on

How to change git branch name (local and remote)

It's possible that we will do something wrong, well, we're all just human, we always do something wrong (or may be right).

Git branch are something that I always define it in wrong pattern 🀣.

Here how to fix it.

  1. you need to change branch name in local first
$ git branch -m old-branch-name new-branch-name
Enter fullscreen mode Exit fullscreen mode

What it does? it dose change local branch name from old-branch-name to new-branch-name. You can check with git log you will found that the old-branch-name are gone!

  1. change branch name in remote

This part are required when the old-branch-name are in remote. What you need to do is just push the new-branch-name into remote then remove the old-branch-name in remote that's it.

$ git push origin -u new-branch-name
$ git push origin -d old-branch-name
Enter fullscreen mode Exit fullscreen mode

Now, the old-branch-name are gone both local and remote.

Top comments (0)

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.