Created
March 8, 2023 18:15
-
-
Save c-dante/ff71955b64d45559982da120c0d82968 to your computer and use it in GitHub Desktop.
Prune local git branches tracking deleted upstreams
This file contains 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 | |
set -Eeuxo pipefail | |
# Update everything, pruning missing upstream first | |
# then list branches with upstreams to capture gone | |
# grep fitlers for the gone branches | |
# awk just the full branch name | |
# xargs offers to delete the branch | |
git fetch --prune --all && git branch -vv | grep ": gone]" | awk '{ print $1 }' | xargs -r -n 1 -p git branch -D |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment