Git-NumberedAdd for PowerShell

Git-NumberedAdd for PowerShell

posted in productivity on

After copying file paths from git status output and pasting them after a git add quite a few times by now, I’ve written a small PowerShell script to stage the files by index.

Git-NumberedStatus (alias: gs)

Displays the output of git status --short together with fabricated indexes like so


Working directory color codes:

  • Yellow: Modified (file0 to file3)
  • DarkMagenta: Deleted (file4)
  • Blue: Added (file5)

Git-NumberedStatus accepts extra CLI arguments. Example: gs -u to see all --untracked-files.
Configure the color output by modifying $global:gitStatusNumbers.

With Numstat

If $global:gitStatusNumbers.includeNumstat is true, Git-NumberedStatus will also execute a git diff --numstat and add lines added/deleted to the output.

Git-NumberedStatus with --numstat

Git-NumberedAdd (alias: ga)

All set to stage some files!

PS> Git-NumberedAdd 0 1 2
add 'file0'
add 'file1'
add 'file2'

The same can be achieved with:

  • Git-NumberedAdd 0-2
  • Git-NumberedAdd -3
  • Git-NumberedAdd 012 (but only if there is a max of 10 files in the git status)

Git-NumberedAdd +3 would add file4 and file5 in the above scenario.

Git-NumberedDiff (alias: gd)

Works like Git-NumberedAdd but can also be called without arguments to see the diff of all files. It will call git add -N for all newly created files so that they also show up in the diff.

git diff --cached is currently not implemented in this script.

Git-NumberedReset (alias: grs)

This only works for files already staged. Example output:


To, for example unstage file0 and file4

PS> Git-NumberedReset 02
Unstaged changes after reset:
M       file0
M       file1
M       file2
D       file4

Other functions

Git-GetFileNameByIndex 2


Sometime similar is actually built into Git itself

git add --interactive # or -i for short

Once in interactive mode:

git add --interactive

And then use 2: Update to stage files.

Also, see below for similar implementations in Bash and Perl.

Stuff that came into being during the making of this post
Other interesting reads
Tags: git powershell