Created
February 12, 2024 21:30
-
-
Save guillaumerocq/99efed8bb48d154d9ada362994af23c4 to your computer and use it in GitHub Desktop.
git alias: local and remote branch deletion
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
[alias] | |
## Local branches ## | |
# deletion of merged branches through bang operator emulation | |
# a deletion is made only if, at least, a branch exists | |
clean-lbranches = "!f() { \ | |
git branch --merged | \ | |
grep -Ewv '^\\*|main|master|develop' | \ | |
xargs -n1 -r git branch -d; \ | |
}; f" | |
# force deletion | |
# /!\ beware, unmerged branches will be deleted /!\ | |
force-clean-lbranches = "!f() { \ | |
git branch --merged | \ | |
grep -Ewv '^\\*|main|master|develop' | \ | |
xargs -n1 -r git branch -D; \ | |
}; f" | |
## Remote branches ## | |
# cleaning and syncing local cache | |
clean-rbranches = "!f() { \ | |
git branch -r --merged | \ | |
grep -Ewv 'main|master|develop' | \ | |
sed 's/origin\\///' | \ | |
xargs -n1 -r git push --delete origin && \ | |
git fetch origin --prune; \ | |
}; f" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment