Interactive git branch switching tool for ZSH with a beautiful UI.
- π― Interactive selection - Navigate branches with ease using gum
- π Rich information - See last commit date, message, and sync status
- π Sync status - View ahead/behind status with remote (ββ)
- π‘οΈ Safety first - Warns about uncommitted changes with stash option
- β‘ Fast navigation - Keyboard-driven interface with search
- π Remote branches - Optionally include and checkout remote branches
- π¨ Beautiful UI - Clean, modern interface with colors
Install gum:
brew install gum- Clone this repository into Oh My Zsh's custom plugins directory:
git clone https://github.com/adelbeke/git-switch-branch.git \
$ZSH_CUSTOM/plugins/git-switch-branch- Add the plugin to your
.zshrc:
plugins=(... git-switch-branch)- Reload your shell:
source ~/.zshrc- Clone the repository:
git clone https://github.com/adelbeke/git-switch-branch ~/git-switch-branch- Source the plugin in your
.zshrc:
source ~/git-switch-branch/git-switch-branch.plugin.zsh- Reload your shell:
source ~/.zshrcgit-switch-branchOr use the short aliases:
gsb # Short alias
gswitch # Alternative aliasgit-switch-branch [OPTIONS]
OPTIONS:
-r, --remote Include remote branches in selection
-c, --create Create and switch to a new branch
-s, --stash Auto-stash changes before switching
-t, --recent Sort by most recently checked out
-h, --help Show help message
-v, --version Show versionSimple branch switch:
git-switch-branchInclude remote branches:
git-switch-branch --remote
gsb -rAuto-stash uncommitted changes:
git-switch-branch --stash
gsb -sCreate new branch:
git-switch-branch --create
gsb -cSort by recent activity:
git-switch-branch --recent
gsb -t- Checks for uncommitted changes - Warns you if you have uncommitted work
- Lists branches - Shows local (and optionally remote) branches
- Displays metadata - Shows commit date, message, and sync status
- Interactive selection - Use arrow keys or search to find your branch
- Safe switching - Performs the git checkout with proper error handling
For each branch, you'll see:
- Branch name - The full branch name
- Last commit time - Relative time (e.g., "2 hours ago")
- Sync status - βX βY showing commits ahead/behind remote
- Last commit message - Truncated to 50 characters
- Uncommitted changes warning - Alerts you before switching with dirty working tree
- Stash option - Offers to stash changes or use
--stashflag - Confirmation prompts - Ask before potentially destructive operations
- Clear error messages - Helpful feedback when operations fail
- Remote tracking - Shows sync status to prevent surprises
Install gum:
brew install gumMake sure you're inside a git repository:
cd /path/to/your/git/repoUse the stash option:
git-switch-branch --stashOr manually stash:
git stash
git-switch-branch
git stash popPair this with git-clean-branches for complete branch management:
- git-switch-branch - Navigate between branches
- git-clean-branches - Delete old branches interactively
Contributions are welcome! Feel free to open issues or submit pull requests.
MIT License - see LICENSE file for details
Built with:
- gum - A tool for glamorous shell scripts
- ZSH - The Z shell
Made with β€οΈ for developers who love efficient workflows
