Is it possible to configure repo-B so that even after a fresh clone remote repositories links [to repo-A] are present?
No.
Remember, git clone
means:
- make a new, empty directory;
- run
git init
in the new empty directory; - run
git remote add
in the new clone; - run
git config
in the new clone if/as directed by options you supplied togit clone
; - run
git fetch
in the new clone; and - run
git checkout
in the new clone.
Only step 4 could do what you want—the git remote add
in step 3 is so that step 5 will fetch from repo-B—and step 4 only obeys arguments you supply on the command line.
You have two options:
- Don’t use
git clone
, at least not directly. Write your own program that runsgit clone
, inspects the new clone, then runsgit remote add
as desired. Or, - Use
git clone
via an alias or script that adds appropriate-c
options so that step 4 sets up a remote.git remote add
consists of running severalgit config
operations: specifically, you must setremote.name.url
andremote.name.fetch
. So you can do these with thegit clone
command line.
Note that both of these are quite similar: the real difference is whether you get repo A’s URL from something retrieved from repo B, or hard-code it. If you choose to get the URL from something retrieved from repo B, remember that git clone
copies all (reachable) commits, but no branches: step 6 is the one that creates a branch in the new clone. You would need to encode repo A’s URL in some data fetched in step 5: probably some commit, perhaps found by a specially coded remote-tracking name (i.e., a branch name in repo-B that becomes a remote-tracking name in your clone), or in some data to be found via some tag name.
CLICK HERE to find out more related problems solutions.