Skip to content

Instantly share code, notes, and snippets.

@cyberplanner
Forked from lttlrck/gist:9628955
Last active July 2, 2017 02:11
Show Gist options
  • Save cyberplanner/fd9716690ff13b65bffaf2ad89d8d739 to your computer and use it in GitHub Desktop.
Save cyberplanner/fd9716690ff13b65bffaf2ad89d8d739 to your computer and use it in GitHub Desktop.
rename git branch locally and remotely

rename git branch locally and remotely

git branch -m old_branch new_branch         # Rename branch locally    
git push origin :old_branch                 # Delete the old branch    
git push --set-upstream origin new_branch   # Push the new branch, set local branch to track the new remote
  1. Rename your local branch. If you are on the branch you want to rename:

git branch -m new-name

If you are on a different branch:

git branch -m old-name new-name

  1. Delete the old-name remote branch and push the new-name local branch.

git push origin :old-name new-name

  1. Reset the upstream branch for the new-name local branch. Switch to the branch and then:

git push origin -u new-name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment