Created
March 10, 2022 17:13
-
-
Save krcm0209/d134971e55e4f0cbdeae2ee1886ffe36 to your computer and use it in GitHub Desktop.
Helper script to delete local git branches which no longer exist on the remote.
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
#!/bin/sh | |
git fetch -p | |
branches_with_gone_remote=$( | |
git for-each-ref --format '%(refname) %(upstream:track)' refs/heads | | |
awk '$2 == "[gone]" {sub("refs/heads/", "", $1); print $1}' | |
) | |
for branch in ${branches_with_gone_remote} | |
do | |
git branch -D $branch | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment