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
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
There are very few occasions where you'd want to checkout remotes/origin/*
. They exist but for the purposes of this shortcut, let's not worry about them. This will get you what you want on OSX:
git config --global alias.sco '!sh -c "git branch -a | grep -v remotes | grep $1 | xargs git checkout"'
You can then issue git sco <number>
to checkout a branch that includes <number>
but excludes "remotes". You can change sco
to be anything you'd like. I just picked it for "super checkout".
Of course this won't work terribly well if you've got more than one branch that matches <number>
. It should, however, be a decent starting point.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With