How to Rename a Local and Remote Git branch?
How to Rename a Local and Remote Git branch?
To rename a local and remote Git branch, you can follow these steps:
Renaming a local branch:
git branch
to list all the branches and see which one you are currently on.git checkout <branch-name>
or create a new branch to switch to.git branch -m <old-branch-name> <new-branch-name>
to rename the local branch. Replace <old-branch-name>
with the current name of the branch and <new-branch-name>
with the desired new name for the branch.Renaming a remote branch:
git push origin :<old-branch-name> <new-branch-name>
to push the renamed branch to the remote repository. Replace <old-branch-name>
with the old name of the branch and <new-branch-name>
with the new name of the branch.
<old-branch-name>
in the command is essential as it indicates the deletion of the old branch.<new-branch-name>
will create a new branch on the remote repository with the renamed branch's contents.git branch -r
to list the remote branches and confirm the changes.Note: When renaming a branch, both locally and remotely, it may impact other collaborators or branches that are based on the renamed branch. Communication and coordination with other team members are crucial to ensure a smooth transition when renaming branches.