Skip to content

@sindresorhus /git-dirty-checks.md
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Benchmark results of the fastest way to check if a git branch is dirty

Tested against the WebKit git repo by entering the repo with 1 file dirty.


git diff --quiet --ignore-submodules HEAD # Will tell if there are any uncomitted changes, staged or not.
0.6 sec

git diff-index --quiet HEAD # Only tracked
2 sec

git diff --shortstat
8.2 sec

git status --porcelain
42 sec

zstyle ':vcs_info:*' check-for-changes true
50 sec

@millermedeiros

git diff --quiet --ignore-submodules HEAD doesn't show the untracked files so it might cause some undesired accidents.

@sindresorhus
Owner

True, but the only git status --percelain will do that, and it's sloooow.

@mathiasbynens

@sindresorhus Doesn’t git status without --porcelain do it too, kind of? That’s what I am using at the moment in my dotfiles: https://github.com/mathiasbynens/dotfiles/blob/9aecb166d67e0119472aceb8bba71b06256929d8/.bash_prompt#L46-L48 (credit to that code goes to @gf3; I stole it from him)

It might be slow, though.

@paulirish

Because it's related... this appears to be the fastest way to check the current branch (used by vcs_info and others)

git symbolic-ref -q HEAD | sed -e 's|^refs/heads/||'
@dideler

@paulirish My (non-scientific) tests show that not using the -q or --quiet option is the fastest, but then you'll probably want to redirect error messages to /dev/null/.

@gjasny

@paulirish Add the --short option and you can get rid of sed:

git symbolic-ref --short HEAD
@artjock

Did you try git status -suno? It's working faster for me and have the same limitations.
Full version is here: https://github.com/artjock/dotfiles/blob/master/bash/config#L20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.