Normally when I issue
git grep
$ cat A
1
$ cd d
$ cat B
1
$ git grep 1
B:1
$ cd ..;git grep 1
A:1
B:1
git grep
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`