find actions are also tests, so you can add tests using -exec:
find . \( ! -name . -exec [ -ef {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print
This applies three sets of actions:
! -name . -exec [ -ef {}/.git ] \; -pruneprunes directories containing a file named.git, except on.(so that you can run the command from the root of a git repository without excluding the whole repository)-name .git -pruneprunes directories named.git(so the command doesn’t search inside the main.gitdirectory of a repository)-printprints anything which isn’t caught by the above.
To only match directories, add -type d, either just before -print, or (to save time processing files):
find . -type d \( \( ! -name . -exec [ -ef {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print \)
Note that toThis also works when run this on a directory other than ., you’ll need to change bothby changing the find start path, and the first test:
find /some/other/path -type d \( \( ! -path /some/other/path -exec [ -e {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print \)
or use -mindepth if your find supports that:
find /some/other/path -mindepth 1 -type d \( \( -exec [ -ef {}/.git ] \; -prune \) -o \( -name .git -prune \) -o -print \)