Skip to content

Instantly share code, notes, and snippets.

@donnyquixotic
Last active December 1, 2023 04:03
Show Gist options
  • Save donnyquixotic/eb7eab6041cd9614348882313579b3ea to your computer and use it in GitHub Desktop.
Save donnyquixotic/eb7eab6041cd9614348882313579b3ea to your computer and use it in GitHub Desktop.
creates git alias `sweep` to prune dead local branches
#!/bin/bash
# description:
# creates git alias 'sweep' that prunes all local branches merged
# into master and optionally, via -f flag, branches that have been merged into
# current branch.
# usage: `git sweep [-f]`
# create alias:
# copypasta script below and or save and run `chmod u+x $HOME/gitSweep.sh | . $HOME/gitSweep.sh`
git config --global alias.sweep \
'!git branch --merged $([[ $1 != "-f" ]] && \
git rev-parse master) | \
egrep -v "(^\*|^\s*(master|develop|dev)$)" | \
xargs git branch -d'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment