Skip to content

Instantly share code, notes, and snippets.

@bencord0
Last active July 13, 2020 10:07
Show Gist options
  • Save bencord0/1df8ab8e3fce0a56c54d986248ac6e76 to your computer and use it in GitHub Desktop.
Save bencord0/1df8ab8e3fce0a56c54d986248ac6e76 to your computer and use it in GitHub Desktop.
Rebase all local branches and scrub those that are already merged.
#!/bin/bash
set -e
git detach origin/master
set +e
mapfile -t BRANCHES < <(git branch | grep -v -e '\*' -e '\+')
for branch in "${BRANCHES[@]}"; do
branch_name="$(echo "$branch"|awk '{print $1}')"
echo "=== $branch_name ==="
git switch "${branch_name}"
git rebase origin/master || git rebase --abort
git detach origin/master
git branch -d "${branch_name}"
done
#!/bin/bash
mapfile -t BRANCHES < <(git branch | grep -v -e '\*' -e '\+')
for branch in "${BRANCHES[@]}"; do
echo "Pushing local branch: ${branch}"
git switch "${branch}"
git push origin +HEAD
done
git switch --detach origin/master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment