From Ryan Armstrong's blog, here's how you do it with GNU find or compatible:
find . -type d -empty -not -path "./.git/*" -exec touch {}/.gitkeep \; find . -type d(recursively) looks for directories under current path-emptyfilters out directories that already contain something-not -path "./.git/*"ensures no files are created inside.gitdirectory-exec touch {}/.gitkeep \;creates empty.gitkeepfile in each directory matching above criteria
The resulting structure looks like
$ tree -a -I .git . ├── .gitignore ├── README.md ├── pom.xml └── src ├── main │ ├── java │ │ └── .gitkeep │ └── resources │ └── .gitkeep └── test ├── java │ └── .gitkeep └── resources └── .gitkeep 7 directories, 7 files