Skip to content

Instantly share code, notes, and snippets.

@sasajib
Forked from grimzy/git-pull-all
Last active August 23, 2024 13:52
Show Gist options
  • Save sasajib/4373229efcbbec5808b5c0722dbebc4a to your computer and use it in GitHub Desktop.
Save sasajib/4373229efcbbec5808b5c0722dbebc4a to your computer and use it in GitHub Desktop.
Git rename local and remote branch
#!/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