Skip to content

Instantly share code, notes, and snippets.

View ddddavidmartin's full-sized avatar

David Martin ddddavidmartin

View GitHub Profile
@ddddavidmartin
ddddavidmartin / .gitconfig
Last active December 7, 2023 21:16 — forked from zdennis/.gitconfig
Git checkout alias that accepts regular expressions
[alias]
co = !"find_and_checkout_branch(){\
for last; do true; done ; \
pattern='^/.*/$' ;\
if [[ $# -eq 1 && $last =~ $pattern ]] ;\
then \
branch_pattern=`echo $last | sed -e 's/^\\///' -e 's/\\/$//'` ;\
branch=`git for-each-ref --sort=-committerdate --format='%(refname:short)' refs/heads/ | grep -E -i $branch_pattern | head -n1` ;\
if [[ $branch ]] ; then \
git checkout $branch ;\