The below co
alias allows you to pass in a basic regular expression (specified by a leading and ending /
) for checking out a recently worked on branch. Falls back to normal checkout
behavior if the given branch name isn't a regex.
With regex:
git co /cool-feature/
Switched to branch 'spike/1234/cool-feauture'
With regex, no matching branch:
git co /non-existent/
No branch found matching /non-existent/
Without regex:
git co spike/1234/cool-feauture
It works as expected (at least how I expect it to work) with multiple arguments:
git co -b my-new-branch-here
git co -b my-new-branch-here parent-branch-here
If you provide more than one argument it doesn't use regular expression matching.
I made it case insensitive by changing
grep
togrep -E -i $branch_pattern
Also, if you have git bash completion installed, add this to your .bash_profile