Created
February 23, 2021 22:21
-
-
Save mrinterweb/6226203167134b8074407cff1444ad98 to your computer and use it in GitHub Desktop.
Easy fuzzy branch switching
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
I rename this to just
sb
so the command is really simple