-
-
Save lbland94/49b553943c5c9125a60f8dc8cf07df22 to your computer and use it in GitHub Desktop.
Git tool to search for a branch. If one match for the string it checks out the branch. If more than one, it lists them.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/local/bin/bash | |
| str="/$*/" | |
| str=$(echo "$str" | sed 's/ /\/ \&\& \//g') | |
| str="print if $str" | |
| res=$(git branch --all | perl -ne "$str") | |
| res=$(echo $res | tr ' ' '\n' | cut -d/ -f3-) | |
| matches=$(echo $res | tr ' ' '\n' | uniq -u | wc -l) | |
| if (( $matches == 1 )); then | |
| git checkout "$res" | |
| else | |
| echo $res | tr ' ' '\n' | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment