Skip to content

Instantly share code, notes, and snippets.

@iwill
iwill / git-cb.sh
Last active October 30, 2023 09:19
git checkout with grep patterns
#!/bin/bash
# alias in gitconfig:
# cb = "!sh ~/.git-cb.sh"
# usage:
# git cb ev lo # *ev*lo* - `develop` will be matched
# cb = "!checkoutbranch() { local branches=`git branch | grep -i $1 | tr -d '* '`; if [[ `echo \"$branches\" | wc -l | tr -d ' '` != 1 ]]; then echo \"Matched multiple branches:\"; git branch | grep --color -i $1; exit 1; fi; git checkout $branches; }; checkoutbranch"
branches=`git branch`