find . -not -wholename "./.git*" -name "*foo*"
or, more strictly, if you do not want to see .git /, but want to search in other dirs, whose name also begins with .git ( .git-foo/bar/...)
find . -not -wholename "./.git" -not -wholename "./.git/*" -name "*foo*"
A bit more complicated, but more efficient, because it truncates the entire .gitdir:
find . -not \( -wholename "./.git" -prune \) -name "*foo*"
source
share