Last active
September 19, 2024 14:50
-
-
Save leodutra/9e7bb9f9a27201db47f9ed0786b5e38b to your computer and use it in GitHub Desktop.
Delete unused local branches ( Git )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
😎