Skip to content

Instantly share code, notes, and snippets.

@buzztaiki
Last active October 12, 2023 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buzztaiki/941003fca9e695d53091755a95ab4377 to your computer and use it in GitHub Desktop.
Save buzztaiki/941003fca9e695d53091755a95ab4377 to your computer and use it in GitHub Desktop.
Git で remote が無くなった local branch を削除する

Git で remote が無くなった local branch を削除する

こんな感じ

git branch --format='%(refname:lstrip=2)%00%(upstream:track)' | awk -F'\0' '$2=="[gone]"{print $1}' | xargs -r git branch -D

alias にしておくと便利

prune-local = !git branch --format='%(refname:lstrip=2)%00%(upstream:track)' | awk -F'\\0' '$2==\"[gone]\"{print $1}' | xargs -r git branch -D

see https://git-scm.com/docs/git-for-each-ref

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment