如何从多个远程位置拉/推? [英] How can I pull/push from multiple remote locations?

查看:23
本文介绍了如何从多个远程位置拉/推?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简短:有没有办法让 git repo 推送到远程存储库列表(而不是单个源")并从中拉取?

The short: is there a way to have a git repo push to and pull from a list of remote repos (rather than a single "origin")?

长期:当我在多台具有不同连接性的计算机上开发应用程序时,我经常遇到这样的情况——比如在运输途中使用笔记本电脑,而在我在途中使用计算机A"某个位置,另一台计算机B"在另一个位置.此外,笔记本电脑可能只与A"或B"连接,有时两者都连接.

The long: I often have a situation when I'm developing an app in multiple computers, with different connectivity – say a laptop while on transit, a computer "A" while I'm in a certain location, and another computer "B" while on another. Also, the laptop might have connectivity with only either "A" or "B", and sometimes both.

我想要的是 git 始终从它当前可以连接的所有计算机拉"和推"到所有计算机,以便更轻松地从一台机器跳转到另一台并继续无缝工作.

What I would like to is for git to always "pull" from and "push" to all the computers it can currently connect to, so it's easier to jump from one machine to the other and continue working seamlessly.

推荐答案

您可以使用 git remote 命令配置多个远程存储库:

You can configure multiple remote repositories with the git remote command:

git remote add alt alt-machine:/path/to/repo

要从所有配置的遥控器中获取并更新跟踪分支,但不合并到 HEAD,请执行以下操作:

To fetch from all the configured remotes and update tracking branches, but not merge into HEAD, do:

git remote update

如果它当前未连接到其中一个遥控器,它将超时或抛出错误,然后继续下一个.您必须从获取的存储库或 cherry-pick 手动合并,具体取决于您希望如何组织收集更改.

If it's not currently connected to one of the remotes, it will take time out or throw an error, and go on to the next. You'll have to manually merge from the fetched repositories, or cherry-pick, depending on how you want to organize collecting changes.

要从 alt 获取 master 分支并将其拉入您当前的头部,请执行以下操作:

To fetch the master branch from alt and pull it into your current head, do:

git pull alt master

所以实际上 git pull 几乎是 git pull origin HEAD 的简写(实际上它在配置文件中查找以确定这一点,但您明白了).

So in fact git pull is almost shorthand for git pull origin HEAD (actually it looks in the config file to determine this, but you get the idea).

要推送更新,您必须手动对每个存储库执行此操作.
我认为,推送的设计考虑到了中央存储库工作流程.

For pushing updates, you have to do that to each repo manually.
A push was, I think, designed with the central-repository workflow in mind.

这篇关于如何从多个远程位置拉/推?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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