Created
September 30, 2024 08:11
-
-
Save frederikstroem/591654278b1f5cb9c15e069db7213ccd to your computer and use it in GitHub Desktop.
Bash alias to list or prune local tracking branches that do not exist on remote anymore.
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
# Source: https://web.archive.org/web/20240930075945/https%3A%2F%2Fstackoverflow.com%2Fquestions%2F13064613%2Fhow-to-prune-local-tracking-branches-that-do-not-exist-on-remote-anymore#17029936 | |
alias git-list-untracked='git fetch --prune && git branch -r | awk "{print \$1}" | grep -E -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk "{print \$1}"' | |
alias git-remove-untracked='git fetch --prune && git branch -r | awk "{print \$1}" | grep -E -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk "{print \$1}" | xargs git branch -d' | |
alias git-remove-untracked-force-unmerged='git fetch --prune && git branch -r | awk "{print \$1}" | grep -E -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk "{print \$1}" | xargs git branch -D' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
git-remove-untracked-force-unmerged
has been added andegrep
has been replaced withgrep -E
.