TheFaceOfBoe TheFaceOfBoe - 1 month ago 32
Git Question

Force Adding Submodule Contents in Git

I'm coding at a school that requires us to submit all of our work to their servers with git. Each assignment has its own folder that has its own .git directory.

I'm trying to make the parent folder push to my github, but when I do push it doesn't actually upload the code inside of the folders because it's considered a submodule. I've tried making a .gitignore file that ignores all .git folders, but that didn't work.

The only solutions I've seen are manually doing git remote every time I want to push the changes inside of a project to my github, or writing a script that syncs the contents of the parent directory with a second directory and then delete all of the .git folders inside before pushing.

Is there any way to cleanly push to github without manually pushing each folder, and without having to make a directory that is essentially a copy of my work just for pushing to github?


To push everything to github,

find -name .git -execdir git push \;

will do it.

If you really want to punch through to the submodules, you can bypass the repositories by adding the contents rather than the submodule:

git rm -rf --cached path/to/submodule     # to clear out any submodule entry
git add path/to/submodule/.

and git won't treat it as a submodule in that repo any more. Now you get to track its contents in two repositories. I've seen this before, but it seems like a lot of work for no concrete benefit I can see. Here's another way to go about it, keeping the submodule boundaries and workflow mostly intact but pushing the submodules to branches in the main one.