如何使用一个遥控器推送到另一个URL并从另一个URL进行拖动? [英] How can I push to one url and pull from another using one remote?

查看:129
本文介绍了如何使用一个遥控器推送到另一个URL并从另一个URL进行拖动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个此存储库的克隆。如果我运行以下命令,我会发现我的本地repo被配置为按照预期使用我的克隆进行抓取/拉取。

I've create a clone of this repository. If I run the following command, I see that my local repo is configured to use my clone to fetch/pull, as expected.

$ git remote show origin
* remote origin
  Fetch URL: https://github.com/domurtag/airbrake-grails.git
  Push  URL: https://github.com/domurtag/airbrake-grails.git

我希望我的本地仓库取代主仓库我从克隆的那个)并推到我的克隆。我做的第一件事就是添加主回购作为远程:

I would like my local repo to instead fetch from the master repo (the one I cloned from) and push to my clone. The first thing I did was add the master repo as a remote:

$ git remote add cavneb https://github.com/cavneb/airbrake-grails.git

如果我再次运行 git remote show来源我看到相同的输出,所以显然我需要做别的事情来表明 cavneb 回购应该用于抓取,但我'我不知道这是什么。

If I again run git remote show origin I see the same output, so obviously I need to do something else to indicate that the cavneb repo should be used for fetching, but I'm not sure what this is.

如果相关,我已经显示了我的 .git / config

In case it's relevant, I've shown the contents of my .git/config below:

[core]
    repositoryformatversion = 0
    filemode = true
    logallrefupdates = true
[remote "origin"]
    url = https://github.com/domurtag/airbrake-grails.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
[remote "cavneb"]
    url = https://github.com/cavneb/airbrake-grails.git
    fetch = +refs/heads/*:refs/remotes/cavneb/*


推荐答案

您正在寻找的命令是:

The command you are looking for is:

git remote set-url origin https://github.com/cavneb/airbrake-grails.git
git remote set-url origin --push https://github.com/domurtag/airbrake-grails.git



<但我强烈建议不要这样做。我不确定,但我会认为这会混淆很多git,因为git假定这是相同的回购协议。所以当你推动时,下一次获取的结果应该改变 - 显然不会这样。

But I would strongly advice against doing that. I am not sure, but I would assume that this will confuse git a lot, because git assumes that this is the same repo. So when you push, the result of the next fetch should change – which it obviously won’t.

处理您的情况的正确方法是将主repo添加为一个额外的远程(我会称它为上游),并且当你想拉它时,只需要:

The proper way to handle your situation is to add the master repo as an extra remote (I would call it upstream), and when you want to pull it, just do:

git fetch upstream
git merge upstream/master

这篇关于如何使用一个遥控器推送到另一个URL并从另一个URL进行拖动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆