The flow is simple:
- I have cloned a repo named project. I have also cloned another repoaddon, embedding it as a submodule withinproject.
- project
--- addon
------ z.c
--- x.c
--- y.c
- I've made changes to some files inside addon. I've committed these changes to bothaddonand the super-projectproject. But I have not pushed them anywhere -- these changes are entirely local.
- Now, I'd like to create a separate branch/worktree of projectat another location, namedotherProject. This new worktree should contain all the parent's files as they are currently, including theaddonsubmodule at its current state, preserving its history.
git worktree add -b otherProject path/to/otherProject HEAD
How do I do this?
Currently, the above command doesn't transfer the submodule. Instead, the new worktree's addon folder is empty.
Some of what I've tried:
- git submodule update --recursivedoes NOT work. When I run it in the new worktree, it tries to fetch the current submodule commit from the original server- origin, which of course fails because the server doesn't have my local- addoncommits. The errors are along the lines of:
error: Server does not allow request for unadvertised object 987e772b2...
fatal: Fetched in submodule path `addon`, but it did not contain  987e772b2...
- git checkout --recurse-submodulesdoes NOT seem to work. It doesn't return any error but when I run- git status -unoafterwards, I get this:
Submodules changed but not updated:
Warn: addon doesn't contain commit 987e772b2...
- I tried changing the new worktree's URL in - .gitmodulesto the local path of the parent repo, but that doesn't help -- it still tries to pull from the remote server. (Some answers seem to imply that one can create submodules from absolute local paths as URL, though this isn't mentioned AT ALL in the docs.)
- Running - git checkoutinside the new worktree's- addonfolder populates it with files -- but these are files taken from the remote server. They do not contain my local changes.
