Skip to content

Instantly share code, notes, and snippets.

@mrinterweb
Created February 23, 2021 22:21
Show Gist options
  • Save mrinterweb/6226203167134b8074407cff1444ad98 to your computer and use it in GitHub Desktop.
Save mrinterweb/6226203167134b8074407cff1444ad98 to your computer and use it in GitHub Desktop.
Easy fuzzy branch switching
#! /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
@mrinterweb
Copy link
Author

I rename this to just sb so the command is really simple

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment