Try it here
Git branch

Rename Git Local and Remote Branches


To rename a branch in Git we should use the git branch command followed by -m option.

  1. If you are required to change the current branch’s name in your project, then run the following:
    git branch -m new-branch
  2. If it is needed to rename another branch in your project, then run the following:
    git branch -m old-branch new-branch
  3. After pushing the <old-branch> branch to the remote repository delete it:
    git push origin --delete <old-branch>
  4. Push the <new-branch> local branch and reset the upstream branch with the git push command:
    git push origin -u <new_branch>

    Or you can use an alternative way:

    git push --set-upstream origin new_branch   # Push the new branch, set local branch to track the new remote

Writer profile pic

Prakash on Jun 25, 2020 at 05:06 am

This article is contributed by Prakash. If you like and would like to contribute, you can write your article here or mail your article to . See your article appearing on the main page and help others to learn.

Post Comment

Comments( 0)


Forgot Password

Please enter your email address below and we will send you information to change your password.