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.
For my work I often haven to open remote branches as well. I have extended the script so that:
The reason for making it interactive is that there are usually a lot more remote branches to pick from, and it can end up matching the wrong one. This way the user can confirm before actually checking it out. Works quite well for me.
I forked the alias here: https://gist.github.com/githubbrowser/7dff9354c841cc51663b