how can i avoid losing remote information when using git?

Is it possible to configure repo-B so that even after a fresh clone remote repositories links [to repo-A] are present?


Remember, git clone means:

  1. make a new, empty directory;
  2. run git init in the new empty directory;
  3. run git remote add in the new clone;
  4. run git config in the new clone if/as directed by options you supplied to git clone;
  5. run git fetch in the new clone; and
  6. 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:

  1. Don’t use git clone, at least not directly. Write your own program that runs git clone, inspects the new clone, then runs git remote add as desired. Or,
  2. 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 several git config operations: specifically, you must set and So you can do these with the git 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.

Leave a Comment

Your email address will not be published.

Scroll to Top