# branch switch tool

An interactive branch switcher for the terminal using fzf. Lists all local and remote branches with a live preview of the last commits — including branches not yet pushed. Download and install to /usr/local/bin to use from any repository.

branch-switch.sh ↓ download
#!/bin/bash
# Lists all local and remote branches with a commit preview
# Local-only branches (not pushed) are included
git branch -a \
| grep -v '\->' \
| sed 's/^[* ]*//; s|remotes/origin/||' \
| sort -u \
| fzf \
--height=40% --reverse --border --ansi \
--prompt='Switch to branch: ' \
--header='All branches [Enter=checkout Esc=cancel]' \
--preview='git log --oneline --color=always -20 "origin/{}" 2>/dev/null
|| git log --oneline --color=always -20 "{}"' \
--preview-window=right:60%
git checkout "$branch"
Manual installation
$ curl -fsSL https://git4.dev/branch-switch.sh \
-o /usr/local/bin/branch-switch.sh
$ chmod +x /usr/local/bin/branch-switch.sh
Requires: git, fzf, curl
Automated — install.sh
$ curl -fsSL https://git4.dev/install.sh | bash
apt-based systems: missing dependencies (git, fzf, curl) are installed automatically
other systems: git, fzf and curl must be installed manually first