Last active
May 16, 2021 19:41
-
-
Save p-karanthaker/5fdc78d78b3d0c6ec9b6655d3e7575b5 to your computer and use it in GitHub Desktop.
Pulls the HEAD branch of all git repos in a directory and deletes branches which are no longer on remote
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
for gitDir in *; do | |
headBranch=$(git -C "$gitDir" symbolic-ref --short HEAD) | |
git -C "$gitDir" checkout "$headBranch" | |
git -C "$gitDir" pull | |
for branch in $(git -C "$gitDir" for-each-ref --format '%(refname) %(upstream:track)' refs/heads | awk '$2 == "[gone]" {sub("refs/heads/", "", $1); print $1}'); do | |
git branch -D $branch | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment