It’s possible this has been asked before, but it’s difficult to tell because submodules seem to cause lots of problems. Here’s what I’m doing.
# cd to parent repo
git submodule add git://example.com/myrepo
cd myrepo
# make some changes
git commit -am "made changes"
cd ..
git commit -am "modified submodule"
git clone --recursive . <path to cloned repo>
When I do this I get errors
fatal: reference is not a tree: 96fa64c0dd64684f86d17841f7c515446885eb33
followed by
Unable to checkout ’96fa64c0dd64684f86d17841f7c515446885eb33′ in submodule path ‘myrepo’
What am I doing wrong here? I just want to add a submodule, then make some changes to it, and then clone the entire parent source tree (including submodule) to a new repo.
You should call
after you add the submodule.
git submodule addclones the repository and adds entries to .gitmodules.git submodule initinitializes the submodules and copies the entries in .gitmodules to .git/configEDIT
I suspect that you have missed some important step in using submodules. Here are the steps that I use to deal with submodules.
First clone the parent repo if applicable
Change to the cloned directory and add your submodule
Initialize all submodules and update all submodules including nested ones
Add all your changes and commit and push to remotes if applicable
This last part is really important as the repo does not really know about your submodule until you commit the changes.