git status Side Effects

Posted on February 17, 2023

TIL, from a conversation with friends1, that git status can indeed have side effects, of some sort.

By default, running git status causes a background refresh of the index to happen, which holds the write lock on the repository.

In theory, if somebody is really unlucky, this could break some script / process that is also trying to work on the repo at the same time, especially on a huge repository where git status takes a significant time, rather than the usual fraction of a second2.

There is a way to prevent this, by running git status --no-optional-locks ( or by setting GIT_OPTIONAL_LOCKS to 0, as writing the updated index is just an optimization and git knows it can be avoided.

I don’t think there are many chances to actually stumble on this in the real life, but I’m writing this down so that if I ever do I have an easy way to remember what happened and find the solution.

  1. I won’t name name or provide details to protect the innocents (and the guilty), but thanks to all of the people involved in the conversations who helped find the answer.↩︎

  2. Related, but unrelated TIL: there is a place called Secondo (second), near Venice, but it’s already a frazione (fraction / subdivision of municipality).↩︎