Guest User

Untitled

a guest
Jan 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. # git checkout branch with simple search
  3. # eg.
  4. # g some-branch
  5. # > git checkout some-branch-with-a-long-name
  6.  
  7. if [ -z $1 ]; then
  8. echo "Usage: g <branch-name>"
  9. exit 1
  10. fi
  11.  
  12. first_match=$(git branch | grep $1 | head -1)
  13.  
  14. if [ -z $first_match ]; then
  15. echo "No branches match $1, soz."
  16. exit 1
  17. fi
  18.  
  19. echo "git checkout $first_match"
  20. git checkout $first_match
  21.  
  22. exit 0
Add Comment
Please, Sign In to add comment