Skip to content

Instantly share code, notes, and snippets.

@goliney
Last active August 30, 2022 01:45
Show Gist options
  • Save goliney/69358109654bd35fced1236e8d372ba0 to your computer and use it in GitHub Desktop.
Save goliney/69358109654bd35fced1236e8d372ba0 to your computer and use it in GitHub Desktop.
Terminal shortcuts for clearing local git branches
# delete all git branches except main
function delete_all_branches_git() {
git checkout main
git branch | grep -v "main" | xargs git branch -D
}
# delete all git branches which start with prefix (except main)
function delete_branches_by_prefix_git() {
git checkout main
git branch | grep -v "main" | grep "$1" | xargs git branch -D
}
# delete fetched branches. Change "serhii/" to your own prefix
function delete_not_mine_branches_git() {
git checkout main
git branch | grep -v "main" | grep -v "serhii/" | xargs git branch -D
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment