Skip to content

Instantly share code, notes, and snippets.

@shoaibi
Created June 25, 2015 15:34
Show Gist options
  • Select an option

  • Save shoaibi/d8e71e24ebd69d129f21 to your computer and use it in GitHub Desktop.

Select an option

Save shoaibi/d8e71e24ebd69d129f21 to your computer and use it in GitHub Desktop.
Rename a git branch
#!/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