Created
May 11, 2012 14:15
-
-
Save softcraft-development/2659937 to your computer and use it in GitHub Desktop.
A ruby shell script to switch git branches based on a regex
This file contains 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/bin/env ruby | |
search = Regexp.new(ARGV[0]) | |
output = `git branch` | |
matching = output.lines.select{ |l| l.match(search) } | |
if matching.size == 0 | |
STDERR.puts "No branch matches #{ARGV[0]}" | |
elsif matching.size == 1 | |
`git checkout #{matching[0].strip}` | |
else | |
puts "Multiple branches matched:" | |
matching.each do |m| | |
puts " #{m.strip}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment