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.

you need to change branch name in lo…


This content originally appeared on DEV Community and was authored by Teerasak Vichadee

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

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

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


This content originally appeared on DEV Community and was authored by Teerasak Vichadee


Print Share Comment Cite Upload Translate Updates
APA

Teerasak Vichadee | Sciencx (2021-10-27T03:20:20+00:00) How to change git branch name (local and remote). Retrieved from https://www.scien.cx/2021/10/27/how-to-change-git-branch-name-local-and-remote/

MLA
" » How to change git branch name (local and remote)." Teerasak Vichadee | Sciencx - Wednesday October 27, 2021, https://www.scien.cx/2021/10/27/how-to-change-git-branch-name-local-and-remote/
HARVARD
Teerasak Vichadee | Sciencx Wednesday October 27, 2021 » How to change git branch name (local and remote)., viewed ,<https://www.scien.cx/2021/10/27/how-to-change-git-branch-name-local-and-remote/>
VANCOUVER
Teerasak Vichadee | Sciencx - » How to change git branch name (local and remote). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/10/27/how-to-change-git-branch-name-local-and-remote/
CHICAGO
" » How to change git branch name (local and remote)." Teerasak Vichadee | Sciencx - Accessed . https://www.scien.cx/2021/10/27/how-to-change-git-branch-name-local-and-remote/
IEEE
" » How to change git branch name (local and remote)." Teerasak Vichadee | Sciencx [Online]. Available: https://www.scien.cx/2021/10/27/how-to-change-git-branch-name-local-and-remote/. [Accessed: ]
rf:citation
» How to change git branch name (local and remote) | Teerasak Vichadee | Sciencx | https://www.scien.cx/2021/10/27/how-to-change-git-branch-name-local-and-remote/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.