Created
June 25, 2015 15:34
-
-
Save shoaibi/d8e71e24ebd69d129f21 to your computer and use it in GitHub Desktop.
Rename a git branch
This file contains hidden or 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/bash | |
| E_BADARGS=65 | |
| if [ $# -ne 2 ]; then | |
| echo "Usage: $0 {old_branch_name} {new_branch_name}" | |
| exit $E_BADARGS | |
| fi | |
| old_branch="$1" | |
| new_branch="$2" | |
| 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