Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@leodutra
Last active April 17, 2024 16:17
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save leodutra/9e7bb9f9a27201db47f9ed0786b5e38b to your computer and use it in GitHub Desktop.
Save leodutra/9e7bb9f9a27201db47f9ed0786b5e38b to your computer and use it in GitHub Desktop.
Delete unused local branches ( Git )
#!/bin/sh
# ref: https://devconnected.com/how-to-clean-up-git-branches/
# 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|master" | xargs git branch -d
# or, for unmerged branches
git branch | egrep -v "^\*|main|dev|master" | xargs git branch -D
@felipe-muner
Copy link

😎

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