in the git config:
git config --global alias.clean-branches "!git branch | grep -v master | xargs git branch -D"
or by edit the config file :
[alias]
# remove all but the mention git
trim = !git branch | grep -v -E 'master|main|development|integration|production' | xargs git branch -D
https://stackoverflow.com/questions/6127328/how-can-i-delete-all-git-branches-which-have-been-merged
# remove all branches which not merged to master
cleanup = "!git branch --merged master | grep -v '\*\|master\|main|production' | xargs -n 1 -r git branch -d"
- Deletes everything except master and the branch I am currently in, just in case.
alias gbDA='git branch | egrep -v "(master|\*)" | xargs git branch -D
- This will remove branches named (e.g.) test-master, master-test:
git branch | grep -ve " master$" | xargs git branch -Dgit branch | select-string -notmatch master | foreach {git branch -d ("$_").Trim() --force}more than 1 branch can be added to the grep expression like "master|develop|current_branch"
rename = branch -m
branches = branch --list
- squash: get all the comments, usage: git squash 3
- squash-m: spesific comment, usage: git squash 3 "feature branch"
- squash-all: use all branch commits, usage: git squash "all my feature branch commits"
squash = "!f(){ git reset --soft HEAD~${1} && git commit --edit -m\"$(git log --format=%B --reverse HEAD..HEAD@{1})\"; };f"
squash-m = "!f(){ git reset --soft HEAD~${1} && git commit --edit -m\"${2}\"; };f"
squash-all = "!f(){ git reset --soft HEAD~$(git count-commits) && git commit --edit -m\"$(1))\"; };f"
# squash-all-branch = "!f(){ git reset --soft HEAD~$(git count-commits) && git commit --edit -m\"$(sed 's/[A-Z]\+/\ &/g' <<< $(git branch --show-current)))\"; };f"
count-commits = rev-list @{1}..HEAD --count