Created
April 1, 2021 07:35
-
-
Save rawiriblundell/25fe461068a29180898ee016c030efe0 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
delete-branch() { | |
local unwanted_branches current_branch mode | |
current_branch="$(git symbolic-ref -q HEAD)" | |
current_branch="${current_branch##refs/heads/}" | |
current_branch="${current_branch:-HEAD}" | |
case "${1}" in | |
(--local) shift 1; mode=local ;; | |
(--remote) shift 1; mode=remote ;; | |
(--both) shift 1; mode=both ;; | |
(*) mode=local ;; | |
esac | |
case "${1}" in | |
('') | |
unwanted_branches=$( | |
git branch | | |
grep --invert-match '^\*' | | |
cut -c 3- | | |
fzf --multi --preview="git log {}" | |
) | |
;; | |
(*) unwanted_branches="${*}" ;; | |
esac | |
case "${mode}" in | |
(local) | |
for branch in ${unwanted_branches}; do | |
git branch --delete --force "${branch}" | |
done | |
;; | |
(remote) | |
for branch in ${unwanted_branches}; do | |
git push origin --delete "${branch}" | |
done | |
;; | |
(both) | |
for branch in ${unwanted_branches}; do | |
git branch --delete --force "${branch}" | |
git push origin --delete "${branch}" | |
done | |
;; | |
esac | |
} | |
delete-branch --local leaf | |
delete-branch --remote leaf | |
delete-branch --both leaf | |
delete-branch leaf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment