Skip to content
sirlisko
Go back

git-branch-switcher

Years ago I wrote a couple of posts with small git tricks: how to see all the changes on a branch, and a one-line command to delete all your merged branches. Both were quick fixes for the same problem: I never remember branch names, and typing them out, or cleaning them up, gets tedious. This time, instead of another snippet, I built a proper tool for it: git-branch-switcher.

What it does

It’s a CLI that wraps the everyday branch operations behind an interactive menu:

It installs as two commands, git-branch-switcher and the shorter br.

Installation

npm install -g git-branch-switcher
# or
pnpm add -g git-branch-switcher

Usage

Switching branches is the default action:

br              # pick a local branch
br -r           # pick a remote branch

Add -s to search instead of scrolling:

br -s           # search local branches
br -r -s        # search remote branches

Deleting works the same way, but with multi-select:

br -d           # delete local branches, asks before deleting unmerged ones
br -D           # force delete, skips that check

br -r -d        # delete remote branches, asks for confirmation
br -r -D        # force delete remote, skips the confirmation

The remote is auto-detected. If you only have one remote, or you have several but one is called origin, it just uses that. If it can’t work out which one to use, it tells you instead of guessing.

Deleting a remote branch runs git push <remote> --delete behind the scenes, so it’s a real operation and hard to undo. That’s why it asks for confirmation unless you pass -D.

How it’s built

It’s written in TypeScript, using simple-git to run the actual git commands, @inquirer/prompts for the interactive menus, and yargs for parsing the flags. Biome handles linting and formatting, and releases go through Changesets: open a PR with a changeset, merge it, and a GitHub Action publishes to npm automatically.

If you find yourself typing git checkout and then squinting at a list of branch names every day, give it a try. The repo has more details, and issues and pull requests are welcome.



Next Post
TreeApp