Simple bash wrapper around git and fzf for interactively search branches( & tags ) and switching (and more) to them.
Do git switch
or git checkout
faster without remembering branch names!
Usage example in GNOME/gtk repository
usage.mp4
Make sure that fzf
is installed.
# on deb-based linux for example
sudo apt-get install fzf
# on mac
brew install fzf
Then copy git-switch-fzf script to some dir that is in your $PATH
variable. See this
Or you can run install.sh
from this repo.
git clone --depth=1 https://github.com/emgyrz/git-switch-fzf ./git-switch-fzf-tmp && \
(./git-switch-fzf-tmp/install.sh || true) && \
rm -rf ./git-switch-fzf-tmp
# default behavior
echo 'alias gco="git-switch-fzf"' >> ~/.zshrc
# search in remotes
echo 'alias gcor="git-switch-fzf --type remote"' >> ~/.zshrc
# update current environment
. ~/.zshrc
gco
# ...it works
Copy from git-switch-fzf --help
Usage: git-switch-fzf [options]
Specify TYPE
of git references where to search.
Can be 'local', 'remote', 'tags' separated with ',' comma.
Default is 'local'.
Short names are 'l', 'r' and 't'
Same as '--type remote'
Command to which the selected value will be passed.
Default is 'git switch'
Return short commit hash instead of branch or tag name
Hide top preview
Print help message
Basic usage without args
git-switch-fzf
Search in all references
git-switch-fzf --type local,remote,tags
# same as
git-switch-fzf -t r,t,l
Search only in tags
git-switch-fzf -type t
Use 'checkout' instead of 'switch'
git-switch-fzf -e "git checkout"
Just print to console selected item name
git-switch-fzf -e echo
Print to console hash of selected item
git-switch-fzf -e echo --take-hash
Use returned value in other command, e.g. for write it to file
echo "selected hash is \$(git-switch-fzf -e echo --take-hash)" > /tmp/test
Tested and works fine on Linux and macOS. Windows - not tested