Skip to content

Instantly share code, notes, and snippets.

@JKirchartz
Created July 3, 2019 17:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JKirchartz/e9fbefa89e1ca4ab97b89d0a943ccdc6 to your computer and use it in GitHub Desktop.
Save JKirchartz/e9fbefa89e1ca4ab97b89d0a943ccdc6 to your computer and use it in GitHub Desktop.
rename git branch
#! /bin/sh
#
# under aliases, add `rename = !~/path/to/git-rename/.sh`
# then to rename the current branch use `git rename <new branch name>`
#
old_branch=$(git rev-parse --abbrev-ref HEAD);
new_branch="$@"
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment