I have a git repo located on my machine at /path/to/repo
, which contains several submodules, /path/to/repo/submoduleA
and /path/to/repo/foo/bar/submoduleB
.
Due to a workflow that I cannot change, the git repo gets copied (as in scp -r) to a remote server, where I work on the code. I want to pull the changes back to the original machine. Cloning/pushing from the remote server isn't an option.
It is tedious to go to each submodule and do
git remote add <name> <url>:/server/path/to/repo/<path to submodule>
Is there a faster way? Something magical like
git remote add --submodules <name> <url>:/server/path/to/repo
executed from the top-level repo that will recurse to each submodule and add the appropriate relative path onto the remote of each submodule? git remote --help
doesn't show anything useful, and neither the Git Pro Book section on submodules.
My best guess is something like
git submodule foreach 'git remote add <name> <url>:/server/path/to/repo/...'
might work, if there there is a way to replace the ...
with the loop-dependent relative path of each submodule in that foreach. I just don't know of such a mechanism built into git submodule foreach
/path/to/repo
, then $sm_path == $diplaypath, right? But if I execute it from a different directory, then they aren't equal, but $sm_path is what I'd need, so wouldn't it be more flexible to just dogit submodule foreach 'git remote add $name <url>:/server/path/to/repo/$sm_path'
? – Arvonio