Skip to content
shellhacks.dev
Command Line

Read a Short Git Status with git status -sb

Read git status -sb at a glance: two columns of codes for index and worktree, and a branch line that shows how far ahead of the remote you are.

1 min read
Summarize in AI

The default git status prints a page of prose, and you want one line per file instead.

Shell
git init -q --bare origin.git
git init -q -b main repo && cd repo
git remote add origin ../origin.git
echo one > a && echo one > c && git add . && git commit -qm first
git push -q -u origin main
echo two >> a && git commit -qam "local only"
echo three >> a
echo new > b && git add b
rm c
echo scratch > d
git status -sb
Text
## main...origin/main [ahead 1]
 M a
A  b
 D c
?? d

-s prints one line per path as two letters, where the first is the state in the index and the second the state in the working tree: A is staged, M is modified but not staged, D is deleted but not staged, MM is both, and ?? is untracked. -b adds the branch line, here main...origin/main [ahead 1]. The codes are listed in the git status manual.

The branch line only knows the state of the remote as of the last fetch, so run git fetch first for a current count. Colors appear only on a terminal. For parsing in a script use --porcelain=v2 -z, whose format is stable across versions and handles names with spaces.

Taggedgit
Share

More snippets

Get new posts by email

One email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.