gitsw
A smart Git branch switcher with automatic stash management and dependency installation.
Features
- Interactive branch picker - Fuzzy search through branches with recent ones first
- Auto-stash on leave - Automatically stash uncommitted changes when switching branches
- Auto-unstash on return - Restore your changes when you come back to a branch
- Dependency sync - Detects package manager changes and prompts to run install
- Recent branches - Quick access to your most recently used branches
- Remote tracking - Easily checkout and track remote branches
Installation
Quick Install (macOS/Linux)
|
From crates.io
From GitHub
From source
Pre-built binaries
Download the latest release for your platform from Releases.
| Platform | Download |
|---|---|
| macOS (Apple Silicon) | gitsw-aarch64-apple-darwin.tar.gz |
| macOS (Intel) | gitsw-x86_64-apple-darwin.tar.gz |
| Linux (x64) | gitsw-x86_64-unknown-linux-gnu.tar.gz |
| Windows (x64) | gitsw-x86_64-pc-windows-msvc.zip |
Usage
Interactive Mode
Just run gitsw without arguments to get an interactive branch picker:
Use arrow keys to navigate, type to filter, Enter to select.
Basic Switching
If you have uncommitted changes, you'll be prompted to stash, discard, or abort.
Create New Branch
Pull After Switch
Track Remote Branch
View Status
Output:
Branch: feature-auth
Changes: 3 modified, 1 untracked
Stash: present
Package manager: npm
Tracking: origin/feature-auth
Recent Branches
Output:
Recent branches:
* [1] feature-auth (current)
[2] main (2 hours ago)
[3] develop [stash] (yesterday)
[4] feature-api (3 days ago)
List Stashes
Shows all branches that have gitsw-managed stashes.
Delete Branch
All Options
Usage: gitsw [OPTIONS] [BRANCH]
Arguments:
[BRANCH] Target branch to switch to (interactive picker if omitted)
Options:
-l, --list List branches with stashes
-r, --recent Show recent branches
-s, --status Show current status (branch, stash, changes)
-d, --delete <BRANCH> Delete a branch (with stash cleanup)
-t, --track <REMOTE/BRANCH> Track and switch to a remote branch
--no-stash Skip automatic stash behavior
--no-install Skip automatic package install
-c, --create Create branch if it doesn't exist
-p, --pull Pull latest changes after switching
-h, --help Print help
-V, --version Print version
Package Manager Support
gitsw automatically detects and handles lock file changes for:
| Package Manager | Lock File |
|---|---|
| npm | package-lock.json |
| yarn | yarn.lock |
| pnpm | pnpm-lock.yaml |
When switching branches, if the lock file has changed, you'll be prompted to run the appropriate install command.
How It Works
- On branch leave: If you have uncommitted changes, gitsw offers to stash them with a branch-specific identifier
- On branch switch: gitsw checks out the target branch
- On branch return: If a stash exists for the branch, gitsw automatically applies and drops it
- Lock file check: Compares lock file hash with stored value, prompts for install if changed
State is stored in .git/git-switch.json within your repository.
Examples
# Daily workflow
# Skip prompts
License
MIT License - see LICENSE for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Development Setup
# Clone the repo
# Install pre-commit hooks
# Build and test
The pre-commit hook will automatically run cargo fmt --check and cargo clippy before each commit.