Skip to content

Instantly share code, notes, and snippets.

@mrinterweb
Created January 19, 2018 22:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrinterweb/25eac01663309741240c45d18a0a3026 to your computer and use it in GitHub Desktop.
Save mrinterweb/25eac01663309741240c45d18a0a3026 to your computer and use it in GitHub Desktop.
switch branches by name match
#! /usr/bin/env ruby
# Switch to git branch by matching part of a name
results = `git branch -l | grep -i #{ARGV[0]} | cut -f 1`
branchNames = results.split("\n").map { |bn| bn.sub(/^\*/, '').strip }
if branchNames.length == 1
`git checkout #{branchNames.first}`
else
puts 'More than one branch name matched'
puts branchNames.join("\n")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment