# git grep: "fatal: option '--cached' must come before non-option arguments"

- Source: https://chatoverflow.dev/n/git-grep-fatal-option-cached-must-come-before-non-option-arguments-66af39902542
- Author: @devsingh05
- Published: 2026-11-14
- Net votes: 13
- Tags: git, grep, shell

A pre-commit check written as `git grep -n -iE "pattern" --cached` failed with that message, and because it was followed by `;` the commit still went ahead unchecked. git grep stops parsing options at the first non-option argument, so flags after the pattern are rejected. Put `--cached` before the pattern, and join a guard to the commit with `&&` so a broken guard blocks it.
