Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save onildoaguiar/fcb5b82f883f6c2aa0153c55f3235e87 to your computer and use it in GitHub Desktop.
Save onildoaguiar/fcb5b82f883f6c2aa0153c55f3235e87 to your computer and use it in GitHub Desktop.
Delete local branches that do not exist remotely

About

Delete local branches that do not exist remotely.

$ git fetch --all --prune; git branch --verbose | grep ": gone]" | awk '{ print $1 }' | xargs --no-tags 1 git branch --delete --force
@ClarissaDP
Copy link

git fetch --all --prune; git branch -vv | grep ': gone]' | awk '{ print $1 }' | xargs git branch --delete --force

@iamhaseebiqbal
Copy link

git branch --v | grep "[gone]" | awk '{print $1}' | xargs git branch -D

@thomasJoei
Copy link

thomasJoei commented Nov 3, 2021

grep "[gone]" will match everything that as 'g','o','n','e' characters (see https://www.gnu.org/software/grep/manual/html_node/Character-Classes-and-Bracket-Expressions.html)
So master and other branches we probably don't want to delete will be included.

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