Link: https://github.com/ingydotnet/git-subrepo
I was thinking about how to distribute configuration (including secrets) in my applications recently so naturally the idea of using git as a way to facilitate the distribution of configuration data pops up. How can I store the configuration in a way that is part of the project repository, but separate so that configuration can be checked out, changed, committed and pushed out as if it were part of the project repository?
Git SubModule, of course. Only problem with git submodule is that you need to manually pull in the config repository once pulling in the project repository. I thought ok, subtrees then, but that brings in its own set of issues and the commands for it are pretty esoteric in my opinion. It just isn't simple to use subtrees. I wanted a way to be able to commit to the configuration repo just like submodules and keep my project repo updated. Bonus would be that it is seamless commit/push from the project repo to the config repo. Guess what, it fucking exists!
Git Subrepo is very nice. Imagine just breaking out a subdirectory as a repository and from your project repo adding and committing as usual. When it comes time to push, you say `git subrepo push <subdir>` and it takes care of pushing changes that you make to the config repo to the remote repository. That is cool. If there are changes on the config repo then you `git subrepo pull <subdir>`. It is that easy.
Users don't need to have git subrepo to checkout your repository. Your Continuous integration pipeline can pull in as usual. This is like https://github.com/mateodelnorte/meta, which is a great way to make large repositories made of smaller repositories work in Git (No I don't believe in the fucking company or team monorepo mumbo, get better tooling).
The one thing I can't say I like about it though is the documentation. Buncha commands, but not enough examples on why I would use something like `git subrepo branch <subdir>`. The other part appears to be some slowness in how it does the operations though that may be because I use Krypton which does authentication and git commit signing.
Simple, how does it work? From what I saw it uses a .gitrepo file to keep track of the last project repository commit it scanned up to and the last sub repository commit that was applied. When you push, it will use some filtering to find changes on the subdirectory from the last project repository commit until now and make a squashed commit on the subdirectory repo and pushes that then makes changes to the .gitrepo file and commits it to the project repo.