1
0
Fork 0
mirror of https://github.com/brzzdev/git-switch.git synced 2026-07-16 16:50:14 +00:00
Interactive Git branch switcher with merged branch cleanup
  • Rust 94.4%
  • Shell 2.9%
  • Just 2.7%
Find a file
2026-06-06 09:50:17 +01:00
.github/workflows ci: update actions to latest major versions 2026-04-01 13:16:10 +01:00
completions feat: add worktree support (git-switch wt) (#47) 2026-05-28 22:38:44 +01:00
shell feat: add worktree support (git-switch wt) (#47) 2026-05-28 22:38:44 +01:00
src fix(picker): use crossterm raw mode for reliable key input 2026-06-06 01:40:11 +01:00
tests feat: add worktree support (git-switch wt) (#47) 2026-05-28 22:38:44 +01:00
.gitignore feat: initial project scaffold 2026-03-12 12:18:57 +00:00
Cargo.lock chore: bump version to 1.0.10 2026-06-06 09:50:17 +01:00
Cargo.toml chore: bump version to 1.0.10 2026-06-06 09:50:17 +01:00
CLAUDE.md feat(just): add release recipe for version bumps and tagging 2026-04-09 14:51:03 +01:00
justfile feat: add worktree support (git-switch wt) (#47) 2026-05-28 22:38:44 +01:00
README.md feat: add worktree support (git-switch wt) (#47) 2026-05-28 22:38:44 +01:00
renovate.json fix(renovate): sync Cargo.lock on dependency updates 2026-04-01 14:14:51 +01:00

git-switch

A fast, interactive Git branch switcher. Pick a branch, fetch & fast-forward it, and clean up merged branches — all in one step.

Features

  • Interactive branch picker — fuzzy-select from local branches (or pass a name directly)
  • Auto-stash — dirty working tree? Changes are stashed before switching and restored after
  • Fast-forward pull — fetches from origin and fast-forward merges, warns if the branch has diverged
  • Merged branch cleanup — prompts to delete local branches that have been merged into the current branch
  • Worktree support — create, switch into, list, and remove worktrees with git-switch wt

Install

Requires Rust and just.

git clone https://github.com/brzzdev/git-switch.git
cd git-switch
just install

This builds a release binary and copies it to ~/.local/bin/git-switch. Make sure ~/.local/bin is on your PATH.

Usage

# Interactive — pick a branch from a list
git-switch

# Direct — switch to a specific branch
git-switch main

Worktrees

# Interactive picker: existing worktrees + branches without one; "Create new: <typed>" when filter matches nothing
git-switch wt

# DWIM — switch into the worktree for `feature`, or create one if it doesn't exist.
# If `feature` doesn't exist as a branch, a new one is created from the remote's default branch.
git-switch wt feature

# List all worktrees
git-switch wt ls

# Remove one or more worktrees (also deletes the branch when it's fully merged;
# a branch with unmerged commits is kept and reported)
git-switch wt rm           # multi-select picker
git-switch wt rm feature   # specific

Worktrees land at ../worktrees/<repo>/<branch> relative to the main checkout. Branch names with slashes (feature/foo) preserve their structure as subdirectories.

Plain git-switch <branch> also knows about worktrees: if the picked branch is already checked out in another worktree, it hands off to that worktree rather than failing with git's "already checked out" error.

Shell integration (required for cd)

A child process can't change its parent shell's directory. Worktree commands print their target path on stdout; a small shell function reads that and runs cd for you.

just install-shell-integration
# Then add the printed line to your shell rc (e.g. ~/.zshrc):
#   source ~/.config/git-switch/git-switch.sh

Without the wrapper, git-switch wt foo still creates / finds the worktree and prints its path — you'd just cd there manually.

Shell Completions

Tab completions are available for zsh, bash, and fish.

just install-completions

This installs the appropriate completion script for your current shell. For zsh, make sure ~/.zsh/completions is in your fpath before compinit:

fpath=(~/.zsh/completions $fpath)
autoload -Uz compinit && compinit

Configuration

Protect branches from the "delete merged branches" prompt by adding them to your Git config:

git config --add git-switch.keep develop
git config --add git-switch.keep staging

License

MIT