npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

git-smart-switch

v0.3.1

Published

A git tool that manages per-branch stashes as you checkout different branches.

Downloads

8

Readme

git-smart-switch

A replacement for git checkout and git switch to make switching between branches easier by:

  • Allow you to checkout a branch via partial matching
  • Automatically managing per-branch stashes

Installation

# With NPM
npm i -g git-smart-switch

# Or with Yarn
yarn global add git-smart-switch

# Then use the following to make a git alias
git config --global alias.ss '!git-ss'

Usage

# Checkout a specific branch. No need to type the entire branch name.
git ss <branch>

# Create and checkout a new branch.
git ss -b <branch>

# List available branches
git ss

Why?

Problem 1: It sucks typing out entire branch names

With git checkout and git switch, you need to type out the entire branch name in order to checkout a different branch.

$ git branch
* develop
  feat/BUG-123-analytics-issue
  feat/BUG-567-app-start-pref
  
$ git checkout feat/BUG-123-analytics-issue
Switched to branch 'feat/BUG-123-analytics-issue'

Better solution: Branch search via git ss

git ss allows you to type the shortest portion of a branch name that disambiguates it from the rest.

$ git branch
* develop
  feat/BUG-123-analytics-issue
  feat/BUG-567-app-start-pref
  
## You could be basic and type out the entire branch name
$ git ss feat/BUG-123-analytics-issue
Switched to branch 'feat/BUG-123-analytics-issue'

## But why not type less?
$ git ss BUG-123
Found branch matching 'BUG-123': feat/BUG-123-analytics-issue.
Switched to branch 'feat/BUG-123-analytics-issue'

## Or even less?
$ git ss 123
Found branch matching '123': feat/BUG-123-analytics-issue.
Switched to branch 'feat/BUG-123-analytics-issue'

## If multiple branches are found, it'll show the branches that match
$ git ss BUG
Found multiple branches matching 'BUG':
  feat/BUG-123-analytics-issue
  feat/BUG-567-app-start-pref

Never type an entire branch name ever again!

Problem 2: Managing stashes sucks

Imagine you currently have my-feature-branch checked out, with several uncommitted changes in there.

Now you want to briefly switch to the develop branch to investigate an issue that has come up.

How will you go about switching branches without disturbing your uncommitted changes?

Solution 1: Stash and unstash manually

## 1) Stash your changes
$ git stash -u

## 2) Switch branch
$ git checkout develop

## 3) Do your stuff on develop
...

## 4) When you're done, switch back and pop your stash
$ git checkout my-feature-branch
$ git stash pop

Solution 2: Commit your changes temporarily

## 1) Make a temporary commit
$ git add .
$ git commit -m 'WIP: Some work on my-feature-branch' --no-verify

## 2) Switch branch
$ git checkout develop

## 3) Do your stuff on develop
...

## 4) When you're done, switch back and undo your commit
$ git checkout my-feature-branch
$ git reset --soft HEAD^

Better solution: Per-branch stashes via git ss

git-smart-switch makes this workflow easy by managing per-branch stash entries.

  • Any time you switch away from a branch using git ss, it will stash the changes for that branch.
  • When you switch back to the branch later, git ss will automatically apply the stash associated with that branch.
## 1) Use 'git ss' to switch branches and stash any changes.
##    'git ss' is smart enough to tie the stash entry to my-feature-branch.
$ git ss develop    # or 'git ss dev' to fuzzy match

Attempting to stash changes for my-feature-branch
Saved working directory and index state On my-feature-branch: smart-switch|my-feature-branch

Switching from my-feature-branch --> develop
Switched to branch 'develop'

## 2) Do your stuff on develop
...

## 3) When you're done, use 'git ss' to switch back
##    'git ss' will notice that there is a smart-switch entry for my-feature-branch and apply it.
$ git ss my-feature-branch    # or 'git ss my-feat' to fuzzy match

Switching from develop --> my-feature-branch
Switched to branch 'my-feature-branch'

Looking for stash to apply to my-feature-branch
Stash found. Applying
 src/first.ts     | 1 +
 src/second.ts.   | 1 +
 2 files changed, 2 insertions(+)