Created
April 26, 2011 15:55
-
-
Save danielmcgrath/942533 to your computer and use it in GitHub Desktop.
Automatic git branch switching based on substrings
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
alias fb="ruby ~/find_branch.rb $1" |
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
# I hate git autocompletion with the white hot intensity of a | |
# thousand burning suns. This works better for me. | |
req = ARGV[0] | |
branches = `git branch | grep '#{req}'` | |
branch_list = branches.split(' ') | |
if branch_list.length > 1 | |
puts | |
puts 'Found the following branches: ' | |
puts | |
branch_list.each_index do |i| | |
puts ' ' + i.to_s + '. ' + branch_list[i] | |
end | |
puts | |
print "Which one do you want? " | |
to_get = STDIN.gets.chomp.to_i | |
`git checkout #{branch_list[to_get]}` | |
elsif branch_list.length == 1 | |
`git checkout #{branches}` | |
else | |
puts "No branch found" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fyi for any bash-newbies who'd visit this: put the first part in your ~/.bash_profile instead.
Other than that this is really awesome.