Skip to content

Instantly share code, notes, and snippets.

@williamluisan
Last active June 22, 2022 03:10
Show Gist options
  • Save williamluisan/d931594562017fba4eb012dac3099b42 to your computer and use it in GitHub Desktop.
Save williamluisan/d931594562017fba4eb012dac3099b42 to your computer and use it in GitHub Desktop.
git prune local branch
(unix-like)
git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -d
(linux)
git branch --merged | egrep -v "(^\*|master|main|dev)" | xargs git branch -d
(windows)
git branch --merged | Select-String -Pattern "develop" -NotMatch | ForEach-Object {git push origin --delete "$_".Trim(); git branch -d "$_".Trim()}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment