Last active
September 23, 2024 18:24
-
-
Save mauriciomutte/7afa8d5caf8c1e66793719b20fd3570a to your computer and use it in GitHub Desktop.
This script automates the cleanup of local Git branches that have already been merged into the current branch. It filters out the main branch and the currently checked-out branch, then deletes the remaining merged branches.
This file contains hidden or 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
git branch --merged | grep -v "^\*\\|main" | xargs -n 1 git branch -d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
git branch --merged
: Lists all merged branches.grep -v "^\*\\|main"
: Filters out the main branch and the current branch (marked with an asterisk).xargs -n 1 git branch -d
: Passes each branch name to git branch -d to delete it.