Is it "safe" for a git clone from one repo and sets a start to another?

So, I have a recent repo clone, I need to work at a "very close" network level (often on a local drive). There is also an “official” server that my workflow really wants to be a source, but it is often very slow (either because it is overloaded, either on a remote network, or both).

(this local repo is a clone of the official server that tends to be outdated for a week or two, but the repo is very large and has about ten years of history imported from old VCS, so the local clone plus fetching from the remote is much faster)

If I git clone -o local /path/to/repo and then git remote add -f origin URI-for-offical-repo , I will return to the same (*) git clone URI-for-offical-repo , given would i?

I am especially afraid of some subtle differences that could make a push from my repo to others. Also, if I start using this clone acceleration method, a “local” repo could be done using this method, possibly for several generations.

(*) the same plus the additional remote name "local" and everything that was not transferred from the local to the official server.

+4
source share
2 answers

Short answer: Yes, probably.

Long answer: Origin is just an alias where you usually want to click. As long as the new destination is associated with the repository from which you pulled out (or an empty repository), and you have write access to it, it should be safe.

NOTE. I really didn’t think your “pseudo-code” example is reasonable. But the concept of cloning and then changing the URL for "origin" is a reasonable concept. I did it myself when the server addresses moved, or I decided to change my public repo location, etc.

Beware if the new origin is NOT a completely empty repository or an old clone of your local repo (without new commits than on your local one) using

 git push --mirror #eg implicitly to "origin" 

can overwrite and delete branches on the remote control if you have full write access to it. (I also succeeded myself when I casually copied and pasted .git / config data from one repo into an unrelated repo. [Fortunately, it had many modern clones, but I sweated for a few seconds when deleting messages it scrolls all over the screen;) ])

+5
source

What you do looks good, but you can find the --reference , which was added to the git clone a while ago. If there is a local copy, it very quickly creates a new clone using repository repository packages, and then simply updates from the network. for example: git clone --reference ./oldercopy $url newcopy

For your current scheme - provided that the tree is connected, there is no problem switching the url for remotes. If they are not related to each other, then all kinds of unpleasant error messages will appear.

+3
source

Source: https://habr.com/ru/post/1380816/


All Articles