Created
November 29, 2023 14:13
-
-
Save nekonado/5c9c1c3fc16acf96fe7f26c827c7cfc6 to your computer and use it in GitHub Desktop.
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/zsh | |
# Fetch changes from the remote repository and prune (delete) remote tracking branches that no longer exist on the remote | |
git fetch --prune && \ | |
# Display a list of local branches and their associated remote branches | |
git branch -vv | \ | |
# Extract lines related to deleted remote branches | |
grep ': gone]' | \ | |
# Extract branch names from the lines that were extracted | |
awk '{print $1}' | \ | |
# Receive branch names and delete the corresponding local branches; the -r option prevents the command from running if there are no arguments | |
xargs -r git branch -d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
one-liner