Skip to content

yigiterdev/git-switch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gitsw

A smart Git branch switcher with automatic stash management and dependency installation.

Crates.io Downloads Rust License

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)

curl -fsSL https://raw.githubusercontent.com/yigiterdev/git-switch/main/install.sh | sh

From crates.io

cargo install gitsw

From GitHub

cargo install --git https://github.com/yigiterdev/git-switch

From source

git clone https://github.com/yigiterdev/git-switch.git
cd gitsw
cargo install --path .

Pre-built binaries

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

Usage

Interactive Mode

Just run gitsw without arguments to get an interactive branch picker:

gitsw

Use arrow keys to navigate, type to filter, Enter to select.

Basic Switching

gitsw main              # Switch to main branch
gitsw feature-auth      # Switch to feature-auth branch

If you have uncommitted changes, you'll be prompted to stash, discard, or abort.

Create New Branch

gitsw -c new-feature    # Create and switch to new-feature

Pull After Switch

gitsw main -p           # Switch to main and pull latest
gitsw -p feature        # Switch to feature and pull

Track Remote Branch

gitsw -t origin/feature-api    # Fetch, create local branch, and track remote

View Status

gitsw -s

Output:

Branch: feature-auth
Changes: 3 modified, 1 untracked
Stash: present
Package manager: npm
Tracking: origin/feature-auth

Recent Branches

gitsw -r

Output:

Recent branches:

* [1] feature-auth (current)
  [2] main (2 hours ago)
  [3] develop [stash] (yesterday)
  [4] feature-api (3 days ago)

List Stashes

gitsw -l

Shows all branches that have gitsw-managed stashes.

Delete Branch

gitsw -d old-feature    # Delete branch (cleans up associated stash)

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

  1. On branch leave: If you have uncommitted changes, gitsw offers to stash them with a branch-specific identifier
  2. On branch switch: gitsw checks out the target branch
  3. On branch return: If a stash exists for the branch, gitsw automatically applies and drops it
  4. 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
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 prompt

License

MIT License - see LICENSE for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Development Setup

# 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 test

The pre-commit hook will automatically run cargo fmt --check and cargo clippy before each commit.

About

a smarter git branch switcher

Resources

License

Stars

Watchers

Forks

Packages

No packages published