I have nested git repos, will it cause a problem

git

A history

  1. I installed etckeeper
  2. I decided to track e.g. shorewall firewall configuration as its own git repository. I think I wanted it to be easier to look at specific configuration changes. I decided I did not need etckeeper any more and uninstalled it. So no conflict, except…
  3. While re-considering etckeeper, I notice I didn't actually remove /etc/.git.

Before I realized, I would have thought that git init would refuse to create a nested git repository.

If I simply resumed using etckeeper, I'd be concerned that the outer git could get bloated tracking the inner .git directories. Alternatively, it might ignore all the files in the directories which are separate git repositories.

So I'm curious, what could possibly go wrong?

Best Answer

My first tests with nested git repositories didn't suffer any of those three problems. You don't have to add .git in gitignore; the contents of all .git directories are ignored automatically.

The other files (e.g. in the same directory as .git) can be committed in the outer repository.

So I thought etckeeper could keep tracking all files, while sub-directories could have their history recorded more carefully in specific repositories. The two histories wouldn't know anything about each other.

I only noticed a problem later. When I committed a directory which is a git repository and contains commits itself, and I hadn't already committed files from that directory in the outer repository, then it appears as a Subproject. The contents are represented only by a commit ID. gitk seems to show it as a Submodule instead.

This sounds like git really wants to recognize them as git-submodule. I don't particularly understand git-submodule, I just know it has a reputation for being a bit confusing.

I also noticed the .etckeeper file bloats up with files from the .git directories, even if git is using submodules.

Related Question