How to ‘flatten’ a Git repository with multiple submodules


A common strategy during development is to use multiple git submodules. In this way you may distribute the workload to other developers but also maintain a proper structure of your project.

However, when it is time to release, a good advice is to ‘flatten’ your repository and ensure that your project is self-contained in a way that there will be no (external) dependency to other repositories which in the future may be deleted (especially if your project depends on repos which are not under your control).

To perform this operation under Linux or Windows (using the linux subsystem) you can use the following command in the root folder of your main repository.

sudo find . -depth -name '.git' -exec rm -r '{}' \;
Disclaimer: The present content may not be used for training artificial intelligence or machine learning algorithms. All other uses, including search, entertainment, and commercial use, are permitted.