This is an example directory structure
ParentRepo/
.git/
parent_file
ChildRepo/
.git/
child_file
child_untracked
I want ParentRepo to track changes of all files under itself (track parent_file
, child_file
, child_untracked
, but don't track ChildRepo/.git
) as if ChildRepo
was not a git repository, but I need to keep ChildRepo
as an git repository
There are three hard requirements
ChildRepo/
and recover it's contents at any point in the history of ParentRepo using only information from the ParentRepo/.git/
directory, without using an external copy of ChildRepo from another server or from backup. Adding ChildRepo as a submodule of ParentRepo is insufficient, since if the entire directory ChildRepo is deleted, there is no way to recover using only the information in ParentRepo. Recovery of ChildRepo/.git/
is not requiredChildRepo/.git/
folderchild_untracked
may not ever make it into the history of ChildRepo, but it should still be possible to track it from ParentRepoCurrently, git treats any directory with a .git/ subdirectory as a git repo and I need to bypass this behavior
These are the reasons for the weird conflicting requirements
Untrack it as a submodule with git rm --cached
, then re-add it as a subdirectory (or rather, add some individual files) using low-level tools:
git update-index --add ChildRepo/child_file
It used to be possible to simply do:
git add ChildRepo/
The trailing /
is important, causing the contents rather than the repository to be added. Unfortunately, in current Git versions this seems to no longer work.
Note that you won't be able to add a .git
subdirectory even if you tried – the exclusion is hardcoded. (But you could git fetch
its branches into the parent to keep a local copy.)