JMRBDev
JMRBDev

Reputation: 347

Github "nested" repositories but not submodules

I want to push a whole folder that has many subfolders in it to a new github repo. The thing is that some of those subfolders contain .git and .gitignore so they are git repos themselves. I would like those subfolders to also be pushed to my new repo, but not as submodules, just as plain folders with their own files inside.

Upvotes: 5

Views: 3303

Answers (1)

torek
torek

Reputation: 490078

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.

Upvotes: 6

Related Questions