Skip to content

Instantly share code, notes, and snippets.

@akuhn
Last active August 13, 2018 19:50
Show Gist options
  • Save akuhn/655c134b34c509333d54 to your computer and use it in GitHub Desktop.
Save akuhn/655c134b34c509333d54 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
if [[ $1 == '' ]]
then
ruby -e 'branches = `git branch`.split($/)' \
-e 'merged = `git branch --merged master`.split($/)' \
-e '(branches & merged).each { |d| d[2...2] = "\e[32m" }' \
-e 'print branches.join("\e[m\n").gsub("* ", "* \e[33m")' \
-e 'puts "\e[m"'
elif [[ $1 == '-' ]]
then
git checkout -
elif [[ $1 == '-c' || $1 == '--current' ]]
then
git branch 2>&- | grep '*' | cut -c 3-
elif [[ $1 == '-d' ]]
then
if [[ $2 == '--all' ]]
then
git branch --merged master | grep -v 'master' | xargs git branch -d
else
git branch -d "$@"
fi
elif [[ $1 == '-D' ]]
then
git branch -D "$@"
elif [[ $1 == '-f' ]]
then
git branch -D "$2"
git checkout -b "$2"
elif [[ $1 == '-m' ]]
then
git branch -m "$2" "$3"
elif [[ $1 == '--remote' ]]
then
git fetch origin "$2":"$2"
git checkout "$2"
else
if [[ `git branch --list "$1"` ]]
then
git checkout "$1"
else
git checkout -b "$1"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment