How to Rename Git branch locally and Remotely

Maybe you’re working on a team where they have a structured naming convention for branches and commit messages, but because you’re new you haven’t really got a hang around it, you were too excited to make your first PR and you pushed your code to the r…


This content originally appeared on DEV Community and was authored by Adetayo Akinsanya

Maybe you're working on a team where they have a structured naming convention for branches and commit messages, but because you're new you haven't really got a hang around it, you were too excited to make your first PR and you pushed your code to the remote repository.

Then you realised that the naming convention for your branch didn't match the one for your team. You don't have to break a sweat, Git has you covered, it allows you to easily rename both your local and remote branches.

This short guide will walk you through the process of renaming the branches

Renaming Git Branch

  • The first thing to do is checking out(switching) to the branch you'd like to rename, incase you are on the branch there is no need to do this, you can proceed to the next step:
git checkout <old_branch_name>
  • Next step is to rename the local branch using the command below
git branch -m <new_branch_name>
  • Then push the new local branch and reset the upstream branch
git push origin -u <new_branch_name>
  • Delete the recently push old remote branch
git push origin --delete <old_branch_name>

And that is is, You've been able to rename both your local and remote branch


This content originally appeared on DEV Community and was authored by Adetayo Akinsanya


Print Share Comment Cite Upload Translate Updates
APA

Adetayo Akinsanya | Sciencx (2022-06-01T22:37:39+00:00) How to Rename Git branch locally and Remotely. Retrieved from https://www.scien.cx/2022/06/01/how-to-rename-git-branch-locally-and-remotely/

MLA
" » How to Rename Git branch locally and Remotely." Adetayo Akinsanya | Sciencx - Wednesday June 1, 2022, https://www.scien.cx/2022/06/01/how-to-rename-git-branch-locally-and-remotely/
HARVARD
Adetayo Akinsanya | Sciencx Wednesday June 1, 2022 » How to Rename Git branch locally and Remotely., viewed ,<https://www.scien.cx/2022/06/01/how-to-rename-git-branch-locally-and-remotely/>
VANCOUVER
Adetayo Akinsanya | Sciencx - » How to Rename Git branch locally and Remotely. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/06/01/how-to-rename-git-branch-locally-and-remotely/
CHICAGO
" » How to Rename Git branch locally and Remotely." Adetayo Akinsanya | Sciencx - Accessed . https://www.scien.cx/2022/06/01/how-to-rename-git-branch-locally-and-remotely/
IEEE
" » How to Rename Git branch locally and Remotely." Adetayo Akinsanya | Sciencx [Online]. Available: https://www.scien.cx/2022/06/01/how-to-rename-git-branch-locally-and-remotely/. [Accessed: ]
rf:citation
» How to Rename Git branch locally and Remotely | Adetayo Akinsanya | Sciencx | https://www.scien.cx/2022/06/01/how-to-rename-git-branch-locally-and-remotely/ |

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.