Skip to content

Instantly share code, notes, and snippets.

@trcook
Last active February 11, 2022 09:29
Show Gist options
  • Save trcook/27c97caa2708cb6ef090 to your computer and use it in GitHub Desktop.
Save trcook/27c97caa2708cb6ef090 to your computer and use it in GitHub Desktop.
how to fix a bunch of nested submodules so that they are subtrees

Submodules and nested submodules

You have a project with a submodule and a nested submodule. it took me a while to figure out how to convert it to subtrees.

why convert to subtrees:

The basic reason is to convert is to make it so that deployment and installation by others is easier and doesn't create as many problems when branching.

basic steps:

The basic process to do this (there are others that involve splitting, but i found this to be easier). in a repo named with a :

  1. run git submodule deinit .
  2. remove the submodule directory and .gitmodules (the whole file or relevent entries)
  3. commit changes (deletion of submodule)
  4. git remote add <remote> <sub module's repo url>
  5. run git subtree add --prefix=<module directory> <remote>
  6. push the repo back out, use a seperate branch if necessarry: git push <remote-name> <branch-name> or git push <remote-name> <local-branch-name>:<remote-branch-name>

the trick

To get this to work in any appreciable way, you need to start with the most deeply nested submodule. Repeat the steps above, push the submodule's parent project out to (wherever), and then move up one and repeat.

The problem with this approach will be if you don't own the relevent submodules. you'll need to fork them first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment