Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Delete unused local branches ( Git )
# Good ref:
# lists branches that can be deleted/pruned on your local. An option --dry-run is needed
git remote prune origin --dry-run
# In order to clean up remote tracking branches,
# meaning deleting references to non-existing remote branches,
# use the “git remote prune” command and specify the remote name
git remote prune origin
# remember: git branch –merged” command takes the HEAD when not provided with a commit SHA
git branch --merged | egrep -v "(^\*|main|dev)" | xargs git branch -d
# or, for unmerged branches
git branch | egrep -v "(^\*|main|dev)" | xargs git branch -D
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment