2021-12-02 13:10:31 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# shellcheck disable=2162
|
|
|
|
|
2022-04-06 07:34:50 +02:00
|
|
|
function delete_local_branch() {
|
2021-12-02 13:10:31 +01:00
|
|
|
git branch -D "$1"
|
|
|
|
}
|
|
|
|
|
2022-04-06 07:34:50 +02:00
|
|
|
function delete_remote_branch() {
|
2021-12-02 13:10:31 +01:00
|
|
|
git push origin --delete "$1"
|
|
|
|
}
|
|
|
|
|
2022-11-27 00:38:11 +01:00
|
|
|
function list_of_the_branches() {
|
|
|
|
echo
|
|
|
|
echo "List of branches:"
|
|
|
|
echo -e "$(git branch)"
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
2023-01-21 21:02:59 +01:00
|
|
|
function remove_branch() {
|
|
|
|
BRANCH="$1"
|
2022-11-27 00:38:11 +01:00
|
|
|
echo "$BRANCH"
|
2021-12-02 13:10:31 +01:00
|
|
|
read -p "Remove locally / remote / both [L/R/B]: " CHOOSE
|
|
|
|
case $CHOOSE in
|
2022-11-27 00:38:11 +01:00
|
|
|
[Bb]*)
|
|
|
|
delete_local_branch "$BRANCH"
|
|
|
|
delete_remote_branch "$BRANCH"
|
|
|
|
unset -f BRANCH
|
|
|
|
;;
|
|
|
|
[Ll]*)
|
|
|
|
delete_local_branch "$BRANCH"
|
|
|
|
unset -f BRANCH
|
|
|
|
;;
|
|
|
|
[Rr]*)
|
|
|
|
delete_remote_branch "$BRANCH"
|
|
|
|
unset -f BRANCH
|
|
|
|
;;
|
|
|
|
*) echo "Please write good answer" ;;
|
2021-12-02 13:10:31 +01:00
|
|
|
esac
|
2023-01-21 21:02:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
BRANCH="$1"
|
|
|
|
|
|
|
|
if [ -z "$BRANCH" ]; then
|
|
|
|
while true; do
|
|
|
|
list_of_the_branches
|
|
|
|
read -p "Select branch to remove: " BRANCH
|
|
|
|
remove_branch "$BRANCH"
|
|
|
|
done
|
|
|
|
else
|
|
|
|
remove_branch "$BRANCH"
|
|
|
|
fi
|