Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
465 views
in Technique[技术] by (71.8m points)

git - 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.

question from:https://stackoverflow.com/questions/65898102/github-nested-repositories-but-not-submodules

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...