How to move Git submodule to sub-directory? – Stack Overflow
Posted by jpluimers on 2020/05/26
It’s a few steps as per [WayBack] How to move Git submodule to sub-directory? – Stack Overflow, so I’m not sure it is the best solution, but it at least works (thanks Philzen):
Had the same problem just the moment ago and ended up deleting the submodule reference (as outlined in this article) and recreating it where i wanted it to go.
To follow your example of moving submodule
jqueryintorepos/jquery
- Delete the (typically three lines) submodule reference from
.gitmodules.- Check
.git/configfor references to the submodule and remove them, if existent- do
git rm --cached jqueryto cut the submodule reference out of the repository- remove the old submodule folder
- recreate you submodule reference (as you possibly did before) with
git submodule add git://github.com/jquery/jquery.git repos/jqueryIn case your submodule was set to specific tag, respectively commit (which you’ll surely have in a stable project) you will have set it again.
Due to this complex process i am strongly hoping there is (or will be, at least on the git roadmap) a more straightforward way of achieving this. If not, surely some scripts could be fumbled together to do this quicker…
References:
- [WayBack] Git Submodules: Adding, Using, Removing, Updating :: Chris Jean
- [WayBack] Git submodules: Specify a branch/tag – Stack Overflow
cd submodule_directory git checkout v1.0 cd .. git add submodule_directory git commit -m "moved submodule to v1.0" git push
–jeroen






Leave a comment