Created
January 19, 2018 22:46
-
-
Save mrinterweb/25eac01663309741240c45d18a0a3026 to your computer and use it in GitHub Desktop.
switch branches by name match
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 | |
# 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