Skip to content

Instantly share code, notes, and snippets.

@pikatenor
Last active April 24, 2019 05:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pikatenor/32816a9fa7d3ff3b051eaa3a31fa7513 to your computer and use it in GitHub Desktop.
Save pikatenor/32816a9fa7d3ff3b051eaa3a31fa7513 to your computer and use it in GitHub Desktop.
git の ブランチを選んで消したり出したりするやつ
#!/bin/bash
set -eo pipefail
RESTORE='\033[00m'
RED='\033[31m'
GREEN='\033[32m'
cmd=${1:-checkout}
option=$2
case $cmd in
delete ) git_cmd="branch --delete" ;;
fetch ) git_cmd="fetch origin" ;;
merge ) git_cmd="merge" ;;
checkout ) git_cmd="checkout" ;;
* ) git_cmd="checkout" ;;
esac
echo
echo -e "You are now on $GREEN$(git branch | grep \* | cut -d ' ' -f2)$RESTORE"
echo
branches=$(git branch | cut -c 2-)
echo -e "Select branch to $RED$git_cmd $option$RESTORE"
select branch in $branches
do
git $git_cmd $option $branch
exit 0
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment