2

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.

JMRBDev
  • 187
  • 12

1 Answers1

1

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.

torek
  • 448,244
  • 59
  • 642
  • 775
  • 1
    Well, I know this is a quite strange situation but I just want to do this because I need to save my files in a repo just not to lose them, and have all of them in one place only. But having sub-repos makes it too complicated. I will try and delete every .git subfolder and that's it! Thank you! – JMRBDev Jan 26 '21 at 11:03