Produced with vhs
Operate on git status entries by numeric index — diff, add, restore, rm, and more.
This tool prints a stable, NUL-safe numbered listing of git status entries (indices start at 0) and lets you run common git actions (diff, add, restore, checkout, rm) by referring to those indices. It supports ranges (2-5), comma-separated lists (0,3,7), staged vs worktree actions, dry-run, and confirmation prompts for destructive actions.
Features
statusprints an indexed list: index, XY porcelain status, and file pathdiff/diff --stagedaddrestore/restore --staged(with confirmation unless--yessupplied)checkout(checkout file from HEAD)rm/rm --cacheddiscardremoves untracked files from disk (with confirmation unless--yessupplied)- Filenames with spaces, special characters, or newlines are supported (uses
git status --porcelain -z)
Example usage
-
Show numbered status: gbn status
-
Diff indices 0 and range 3-5: gbn diff 0,3-5
-
Add index 4: gbn add 4
-
Restore from index 2 (staged version): gbn restore -s 2
-
Delete untracked files at indices 1-5: gbn discard 1-5
The demo GIF is generated using vhs. To regenerate it:
-
Install vhs:
brew install vhs
-
Run vhs on the tape file:
vhs demo.tape
This will output a new demo.gif in the current directory.
This project uses bats-core for testing.
On macOS with Homebrew:
brew install batsOn Linux:
# Debian/Ubuntu
sudo apt-get install bats# Run all tests
bats gbn-tests.bats-
Ensure you have a directory in your PATH, e.g.
~/bin:mkdir -p ~/bin echo 'export PATH="$HOME/bin:$PATH"' >> ~/.zshrc source ~/.zshrc
-
Copy the script into
~/binand make it executable:curl -o ~/bin/gbn https://raw.githubusercontent.com/miccou/git-by-numbers/main/gbn chmod +x ~/bin/gbn