My objective is to simplify the process of updating my git mirror clones.
I have a git repository repo-A which is given by a supplier
I have a git repository repo-B which is in my local git
I am able to clone repo-A add repo-B as a remote and push to repo-B. With this commands
git clone --mirror repo-A
git remote add my-local-server repo-B
git push --mirror my-local-server
The result is that repo-B contains the same branches, commits, etc than repo-A. At this point I can fetch new code from repo-A and push it to repo-B
The problem is that if I clone repo-B in another computer. The configuration of the remotes is lost.
This means that if I do a git remote -v only the links to repo-B are present.
Is it possible to configure repo-B so that even after a fresh clone remote repositories links are present?
My objective is to be able to do
git clone repo-B
git fetch --all origin /* or the name of location repo-A is located */
git push --all my-local-server
I know that a similar behaviour can be achieved by
git clone --mirror repo-A
git push --mirror repo-B
No.
Remember,
git clonemeans:git initin the new empty directory;git remote addin the new clone;git configin the new clone if/as directed by options you supplied togit clone;git fetchin the new clone; andgit checkoutin the new clone.Only step 4 could do what you want—the
git remote addin 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:
git clone, at least not directly. Write your own program that runsgit clone, inspects the new clone, then runsgit remote addas desired. Or,git clonevia an alias or script that adds appropriate-coptions so that step 4 sets up a remote.git remote addconsists of running severalgit configoperations: specifically, you must setremote.name.urlandremote.name.fetch. So you can do these with thegit clonecommand 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 clonecopies 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.