How to git grep in the whole tree when I'm in a subdirectory?

:/ magic path

git grep pattern -- :/

works on Git 1.9.1 for this and other commands, as mentioned at: https://stackoverflow.com/a/31696782/895245

TODO I can't find a clear documentation reference after grepping the docs, but it is mentioned some times in the release notes at:

Documentation/RelNotes/1.7.6.txt:39: be a no-op, but "git add -u :/" would add the updated contents of


Git aliases that run shell commands are always executed in the top level directory (see the git config man page), so you can add this to your .gitconfig file:

[alias]
    rgrep = !git grep

Alternatively, you could use git rev-parse --show-toplevel to get the root directory, which you could then pass to git grep as the basis of a script or alias:

git grep $pattern -- `git rev-parse --show-toplevel`

Tags:

Git

Grep