从多个远程位置拉/推 [英] pull/push from multiple remote locations

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

问题描述

:有没有办法让git仓库推送到远程仓库列表(而不是单个原点)?

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



我想让git始终拉从推到它当前可以连接的所有计算机,因此更容易从一台计算机跳到另一台计算机,并继续无缝工作。 解决方案

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

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

从所有配置的远程和更新跟踪分支,但不合并到HEAD,做:

  git远程更新

如果当前没有连接到其中一个遥控器,它将需要时间或发生错误,然后继续下一个。您必须从提取的存储库手动合并,或根据您希望组织收集更改的方式进行手动合并。



要从alt和把它拉进你当前的头,做:

  git pull alt master 

所以实际上 git pull 几乎是的缩写,git pull origin HEAD (其实它看起来在配置文件中来确定这一点,但你明白了)。

对于推送更新,你必须对每个手动回购。我认为,设计时考虑了中央资料库工作流程。


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")?

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.

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.

解决方案

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

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

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

git remote update

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.

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

git pull alt master

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天全站免登陆