Git Rename Local and Remote Branch


GIT Rename Local Branch:

To rename a local branch in Git, you can use the git branch command with the -m option, followed by the old branch name and the new branch name

Here is an example of how to rename a local branch

List all local branches:

git branch

Rename the local branch by using the -m option, followed by the old branch name and the new branch name:

git branch -m old-branch new-branch

Verify that the local branch has been renamed:

git branch

GIT Rename Remote Branch:

Let change remote branch dev to dev_v1

To rename a remote branch in Git, you can follow these steps:

First, ensure that you have a local copy of the remote branch by checking out the branch:

git checkout <remote-branch-name>

Rename the local branch using the following command:

git branch -m <new-branch-name>

Push the renamed branch to the remote repository using the following command.This will set up tracking for the new branch and push the changes to the remote repository.

git push origin -u <new-branch-name>

Finally, delete the old branch on the remote repository:

git push origin --delete <old-branch-name>

Consolidated Commands to rename from dev to dev_v1

$ git checkout dev

$ git branch -m dev_v1

$ git push origin -u dev_v1

$ git push origin --delete dev