Skip to content

Instantly share code, notes, and snippets.

@tsterker
Last active December 21, 2015 00:48
Show Gist options
  • Save tsterker/6222942 to your computer and use it in GitHub Desktop.
Save tsterker/6222942 to your computer and use it in GitHub Desktop.
# helpers
function branchExists(){ git show-ref --verify --quiet refs/heads/"$1"; }
function currentBranch(){ git rev-parse --abbrev-ref HEAD; }
function isCurrentBranch() { [ "$(currentBranch)" == "$1" ]; }
# colors
Color_Off='\e[0m' # Text Reset
BWhite='\e[1;37m' # White
Red='\e[0;31m' # Red
function whitePrompt(){ echo -en "${BWhite}$@${Color_Off}"; read value; }
function whiteEcho(){ echo -e "${BWhite}$@${Color_Off}"; }·
function redEcho(){ echo -e "${Red}$@${Color_Off}"; }
function gib()
{
# Usage:
# gib list branches
# gib <branch> switch to branch or create if not exists
# gib <branch> ! delete branch
branch="$1"
optParam="$2"
if [ -z $branch ]; then
whiteEcho "/ usage: gib [branch] [!]"
whiteEcho "\-------------------------/"
git branch --all --color
elif ! branchExists $branch; then
redEcho "Branch $branch does not exist."
whitePrompt "Want to create it? <RET>"
git checkout -b $branch
elif [ "$optParam" == "!" ]; then
if isCurrentBranch $branch; then
redEcho "Can not delete branch you are currently on."
whitePrompt "Switch to branch master and delete '$branch'?"
git checkout master
else
whitePrompt "Delete branch '$branch'? <RET>"
fi
git branch -d $branch
else
git checkout $branch
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment