If I have the following branches in git
1194-qa-server
master
remotes/origin/1178-authentication
remotes/origin/1194-qa-server
remotes/origin/HEAD -> origin/master
remotes/origin/master
I want to switch to a branch using --just-- the number, even if that requires calling a script For example:
switch_branch 1178
and the script/solution should do the following
- git branch -a (find all branches local and remote in my repository)
- filter by the given parameter ('1178' above)
- extract the name of the branch that git can use
- switch to that branch
What is the recommended way to do it without having to perform all these steps manually?
I am using Mac OSX, if that matters here.
update -- bash-it (github.com/revans/bash-it) serves my purpose
Welcome to Bash It!
Here is a list of commands you can use to get help screens for specific pieces of Bash it:
rails-help list out all aliases you can use with rails.
git-help list out all aliases you can use with git.
todo-help list out all aliases you can use with todo.txt-cli
brew-help list out all aliases you can use with Homebrew
aliases-help generic list of aliases.
plugins-help list out all functions you have installed with bash-it
bash-it-plugins summarize bash-it plugins, and their installation status
reference <function name> detailed help for a specific function
Here is my solution with fuzzy checkout: Add the alias to your
~/.gitconfig
by runThe command above will add the alias to your
~/.gitconfig
:The alias can have 2 parameters for the fuzzy matching, you can use it like:
It will find the checkout the branch first match
For example, if you want to checkout your branch 1178, you can run:
the alias fc supports two parameters, if you want more accurate matching, you also can run:
You also can find my other favorite snippets here