Can anyone explain, why “git status” touches the .git directory?

I currently maintain a project for a git-prompt for bash ( and I just got a bug report ( from someone who works with Docker, who tells me, that everytime he uses the prompt, the cache is invalidated, because the .git directory is constantly touched.

I have looked into this, and found out, that it is the command git status, which touches the .git directory.
It seems, that only the directory entry itself and no contents are touched.
Can anyone explain, why this is needed, or is this maybe a bug in Git.

  • Release notes from git log using bash awk
  • Conflict between branch and file completion in bash/git
  • Getting git return values in shell script
  • How to git add all files in current project, commit, and do a push?
  • Keep being prompted to enter passphrase for .ssh/id_rsa
  • Python 3 Wont run from the Git Bash command line
  • Is there a way to show all status info, without touching the .git directory?

    Thanks for the help


    Since the whole reason to use the git status command was, to determine the number of untracked files, I replaced it with git ls-files --others --exclude-standard | wc -l, which doesn’t need a lock.

  • Why is Jenkins getting Authentication Failed error for git submodule update?
  • git svn ambiguous argument 'HEAD'
  • Git, ignored files appear in every branch
  • Git contains between arbitrary commits
  • SSH Public key denied on “git clone” command
  • How to prevent checked-in files from overwriting local versions?
  • One Solution collect form web for “Can anyone explain, why “git status” touches the .git directory?”

    strace git status shows that this action uses the lock file .git/index.lock, that’s why the .git‘s mtime is updated.

    git being cool, it uses the environment variable GIT_INDEX_FILE to decide which lock file to use. If unset, git uses.git/index (this is the default), but if set, git uses its value. From man git:


    This environment allows the specification of an alternate index file. If not specified, the default of $GIT_DIR/index is used.


    GIT_INDEX_FILE=banana git status

    will not update your .git‘s mtime.

    So you now have to make a decision as whether you want to go along this path or not (which certainly has many caveats).

    Good luck!

    Git Baby is a git and github fan, let's start git clone.