Created
July 3, 2019 17:30
-
-
Save JKirchartz/e9fbefa89e1ca4ab97b89d0a943ccdc6 to your computer and use it in GitHub Desktop.
rename git branch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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