Can Git Remotes be Cascaded?

2019-07-25 02:47发布

问题:

My Windows Computer: Has a local git repository (R1) for a Visual Studio project. The remote (origin) for this repository is GitHub. They are identical with just a Master branch. (All of the commits have been pushed to GitHub.)

NAS (local y: drive): Has an unused git repository (R2) that was created "init --bare" and nothing else has happened here.

What I would like to do (I think) is have the R2 the origin remote of R1, and GitHub the origin remote of R2. Development would occur in R1 (or other R1.x on different PCs) with commits pushed to R2. When it makes sense, the R2 branch(es) would be pushed to GitHub.

What I am not exactly sure about is how I get from where I am to where I want to be without making a mess of things. Any help/direction would be most welcome. Thanks, Jon

回答1:

On your R1 repo: git remote set-url origin path_to_R2

On your R2 repo: git remote add origin url_to_github_repo and then git fetch

Done.