git fetch from a a second degree remote
I have a very slow network link to my remote repository (call it repoSlow) from which I fetch once in a while to my main development repo (call开发者_如何学JAVA it repo1).
Sometimes I clone repo1 to repo2 in another directory to do tests e.g. on other branches without losing the state of repo1 (also concerning object files and libraries, therefore a simple stash won't do it).
In order to get the state of repoSlow into repo2 I have usually to stash in repo1, checkout and merge every branch (I am interested in) from repoSlow to repo1, then fetch them to repo2.
Besides the fact that it is a cumbersome procedure and some other points, I sometimes don't want to merge in repo1. Checking out to a different local branch name will result in a big naming mess.
Is there an easy and direct way to in fact fetch the remote of a remote?
I guess that a better workflow might be to clone repoSlow to a bare (or even mirrored?) local repo and clone that one multiple times, but for the sake of better understanding git I maintain the original question.
You are right, it would probably be best to clone to a bare repo locally as your integration point, and then clone your repo1 and repo2 from that.
But to answer your original question, I don't believe that there is a way to directly fetch the remote of a remote; but you could just add repoSlow as a remote in repo2 after cloning it from repo1. If you do that, it will only have to fetch from repoSlow the things that it didn't clone from repo1, which should be considerably faster than fatching the full history.
To do this, just run the following from within repo2:
git remote add upstream git://example.com/path/to/repo/slow.git
git remote update
Now you should have two remotes in repo2; origin
referring to repo1, and upstream
(or whatever you want to call it) pointing to your repoSlow.
You can make a configuration like this in repo2:
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
fetch = +refs/remotes/origin/*:refs/remotes/ancestor/*
This tells repo2 to not only fetch repo1's branches (and mirror them as origin/*
) but also to fetch repo1's tracking branches of its origin (and mirror them as ancestor/*
)
So now you need only do a "git fetch" in repo1 to fetch changes from repoSlow, without changing any local branches at all, and then you will be able to fetch those changes into repo2 as well.
精彩评论