You can't.
Really?
Well, OK, you mostly can't.
A Git repository cannot contain another Git repository. The .git
directory within any sub-directory tells the outer Git that the inner repository is a repository.1 Git will refuse to add it except as a submodule. You can rename or remove the .git
directory, hence making the subdirectory no longer contain a Git repository. Once the inner working-tree is just a tree, not a repository, you can add it. Now it's just files, not commits, so everything is OK. If you're OK with that, do that; it's trivial to achieve. (This makes me wonder why you posted this as a question.)
There is also git subtree
: see When to use git subtree?
1It's slightly more complicated than that, but the effect is about the same. The reason the outer Git won't store an inner Git repo is that if it did, you could make a repo that, when cloned, contains another repo with a pre-loaded .git/config
file. This .git/config
file could contain security-breaking instructions that would cause security to be broken. So Git refuses to save anything named .git
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…