Source: Stackoverflow
On Linux and OS X the following command is possibly the fastest (ignoring repositories without .git) when the root directory of find is /:
find / -name .git -exec dirname {} \; -prune
But for roots that have mostly repositories underneath, the following is probably the fastest (you may want to replace / with . or another root):
find / -type d -exec test -d {}/.git \; -prune -print
Quick explanation of the primaries of find used (since no operators are present here, -and is implicit, i.e., for each visited node primaries are evaluated left to right until one of them evaluates to false):
-nameistrueif the name matches (often, but not here, with wildcards)-execexecutes a command terminated by;(which is escaped by\to avoid interpretation by the shell), and istrueif the return status is0(i.e., OK). The current node is available as{}(which needs no escaping)-pruneis alwaystrue, and causes all child nodes to be skipped-type distruefor directories-printis needed here because if-execis present it is not implicitly appended