Skip to content

Interactive search for branches and switching between them. Interactive 'git switch'/'git checkout'

Notifications You must be signed in to change notification settings

emgyrz/git-switch-fzf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

git-switch-fzf

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!

screenshot

Usage example in GNOME/gtk repository
usage.mp4

Install

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

(Optional) Add short alias

# 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

Usage

Copy from git-switch-fzf --help

Usage: git-switch-fzf [options]

Options

-t, --type TYPE

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'

-r, --remote

Same as '--type remote'

-e, --exec CMD

Command to which the selected value will be passed.

Default is 'git switch'

--take-hash

Return short commit hash instead of branch or tag name

--no-preview

Hide top preview

-h, --help

Print help message

Examples

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

About

Interactive search for branches and switching between them. Interactive 'git switch'/'git checkout'

Topics

Resources

Stars

Watchers

Forks

Languages