Removing submodule status for many subfolders to commit one large repository to Github

12 Views Asked by At

I have a folder stored locally which contains many, many subfolders all of which are/were their own repositories. It's all of the lectures, exercises, etc. from school - when I graduated and had to return my school laptop, before my school Gitlab account was shut down, I simply copied the root folder onto a flash drive and then transferred it to my personal computer, planning to add them to my Github later. In retrospect I realize this was not the best way to go about it; I was in a rush (we were given explicit permission to keep copies of everything by the way).

Right now I have this massive folder called "LecturesExercisesEtc" which I've init/commit/push'd to a new private repository on Github, but Git recognizes each folder it contains as repositories (many of which themselves contain repositories) so essentially the root repository is currently just a handful of empty folders on Github.

I just want these on my Github for record keeping and safe storage; I don't care about previous commit history for the individual projects (the important ones I've already extracted out into their own separate repositories). Is there any way to tell git to ignore nested repositories/submodule status and push all contents to the root repository, without having to go through and manually delete git files for hundreds of lectures and exercises?

Any help would be much appreciated!

1

There are 1 best solutions below

0
On

You could look at the absorbgitdirs command for git-submodule, but I don’t think it does exactly what you asked for. If I understand your question, it sounds like you want to collapse all the nested repositories; absorbgitdirs keeps them as separate repositories, and just moves them all to the top-level .git directory.

The simplest solution might be to script your way through removing the .git directories for the nested repositories, rather than trying to do something clever with Git.

find * -type d -name ‘.git’ -exec mv -i “{}” “{}_old” \;

By default, * shouldn’t match hidden directories like .git, which should keep it from renaming the top-level .git directory. Then you could just add everything, but ignore the .git directories by Then add “.git_old” to the .gitignore file, and use git add . to add everything to the top-level repository.