A smart Git branch switcher with automatic stash management and dependency installation.
- 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
curl -fsSL https://raw.githubusercontent.com/yigiterdev/git-switch/main/install.sh | shcargo install gitswcargo install --git https://github.com/yigiterdev/git-switchgit clone https://github.com/yigiterdev/git-switch.git
cd gitsw
cargo install --path .Download the latest release for your platform from Releases.
| Platform | Download |
|---|---|
| macOS (Apple Silicon) | gitsw-aarch64-apple-darwin.tar.gz |
| Linux (x64) | gitsw-x86_64-unknown-linux-gnu.tar.gz |
| Windows (x64) | gitsw-x86_64-pc-windows-msvc.zip |
Note: For macOS Intel, use
cargo install gitsw
Just run gitsw without arguments to get an interactive branch picker:
gitswUse arrow keys to navigate, type to filter, Enter to select.
gitsw main # Switch to main branch
gitsw feature-auth # Switch to feature-auth branchIf you have uncommitted changes, you'll be prompted to stash, discard, or abort.
gitsw -c new-feature # Create and switch to new-featuregitsw main -p # Switch to main and pull latest
gitsw -p feature # Switch to feature and pullgitsw -t origin/feature-api # Fetch, create local branch, and track remotegitsw -sOutput:
Branch: feature-auth
Changes: 3 modified, 1 untracked
Stash: present
Package manager: npm
Tracking: origin/feature-auth
gitsw -rOutput:
Recent branches:
* [1] feature-auth (current)
[2] main (2 hours ago)
[3] develop [stash] (yesterday)
[4] feature-api (3 days ago)
gitsw -lShows all branches that have gitsw-managed stashes.
gitsw -d old-feature # Delete branch (cleans up associated stash)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
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.
- 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.
# Daily workflow
gitsw # Pick branch interactively
gitsw main -p # Update main branch
gitsw -c fix/bug-123 # Start new bugfix branch
gitsw -r # See recent branches
gitsw -t origin/release # Track release branch from remote
# Skip prompts
gitsw main --no-stash # Switch without stashing (may fail with conflicts)
gitsw feature --no-install # Switch without install promptMIT License - see LICENSE for details.
Contributions are welcome! Please feel free to submit a Pull Request.
# Clone the repo
git clone https://github.com/yigiterdev/git-switch.git
cd gitsw
# Install pre-commit hooks
./scripts/setup-hooks.sh
# Build and test
cargo build
cargo testThe pre-commit hook will automatically run cargo fmt --check and cargo clippy before each commit.