Skip to content

Instantly share code, notes, and snippets.

@mauriciomutte
Last active September 23, 2024 18:24
Show Gist options
  • Save mauriciomutte/7afa8d5caf8c1e66793719b20fd3570a to your computer and use it in GitHub Desktop.
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.
git branch --merged | grep -v "^\*\\|main" | xargs -n 1 git branch -d
@mauriciomutte
Copy link
Author

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.

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