-
-
Save sasajib/4373229efcbbec5808b5c0722dbebc4a to your computer and use it in GitHub Desktop.
Git rename local and remote 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
#!/usr/bin/env sh | |
# usage git-branch-rename.sh <oldName> <newName> | |
# make code up to date | |
git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done | |
git fetch --all | |
git pull --all | |
oldName=$1; | |
newName=$2; | |
git checkout "$oldName"; | |
git pull origin "$oldName"; | |
git branch -m "$newName"; | |
git push origin -u "$newName"; | |
git push origin --delete "$oldName"; | |
echo "renamed branch $oldName to $newName"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment