Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
375 views
in Technique[技术] by (71.8m points)

git - 从多个远程位置拉/推(pull/push from multiple remote locations)

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

(简短的说:有没有办法将git repo推送到远程仓库(而不是单个“来源”)列表并从中提取?)

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.

(冗长的话:当我在多台计算机上开发具有不同连接性的应用程序时经常遇到这种情况–例如在运输过程中的便携式计算机,在特定位置的计算机“ A”和另一台计算机“ B”而在另一个。)

Also, the laptop might have connectivity with only either "A" or "B", and sometimes both.

(另外,笔记本电脑可能仅与“ A”或“ B”(有时两者)具有连接。)

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始终从其当前可以连接的所有计算机“拉”和“推”到它,因此从一台机器跳到另一台机器并继续无缝地工作更容易。)

  ask by Zorzella translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Doing this manually is no longer necessary , with modern versions of git !

(对于现代版本的git不再需要手动执行此操作 !)

See Malvineous 's solution, below.

(请参阅下面的Malvineous解决方案。)

Reproduced here:

(转载于此:)

git remote set-url origin --push --add <a remote>
git remote set-url origin --push --add <another remote>

Original answer: (原始答案:)

This something I've been using for quite a while without bad consequences and suggested by Linus Torvalds on the git mailing list .

(我已经使用了相当长的时间了,但并没有造成严重的后果,由git邮件列表上的Linus Torvalds提出。)

araqnid ’s solution is the proper one for bringing code into your repository… but when you, like me, have multiple equivalent authoritative upstreams (I keep some of my more critical projects cloned to both a private upstream, GitHub, and Codaset), it can be a pain to push changes to each one, every day.

(araqnid的解决方案是将代码引入您的存储库的合适解决方案……但是当您像我一样拥有多个等效的权威上游时(我将一些更重要的项目克隆到了私有上游,GitHub和Codaset中),每天都要对每个更改进行更改可能会很痛苦。)

Long story short, git remote add all of your remotes individually… and then git config -e and add a merged‐remote.

(长话短说, git remote add所有的远程…,??然后git config -e并添加合并的远程。)

Assuming you have this repository config :

(假设您具有此存储库config :)

[remote "GitHub"]
    url = [email protected]:elliottcable/Paws.o.git
    fetch = +refs/heads/*:refs/remotes/GitHub/*
[branch "Master"]
    remote = GitHub
    merge = refs/heads/Master
[remote "Codaset"]
    url = [email protected]:elliottcable/paws-o.git
    fetch = +refs/heads/*:refs/remotes/Codaset/*
[remote "Paws"]
    url = [email protected]:Paws/Paws.o.git
    fetch = +refs/heads/*:refs/remotes/Paws/*

… to create a merged‐remote for "Paws" and "Codaset" , I can add the following after all of those:

(…为"Paws""Codaset"创建合并的远程"Codaset" ,我可以在所有这些之后添加以下内容:)

[remote "Origin"]
    url = [email protected]:Paws/Paws.o.git
    url = [email protected]:elliottcable/paws-o.git

Once I've done this, when I git push Origin Master , it will push to both Paws/Master and Codaset/Master sequentially, making life a little easier.

(完成此操作后,当我git push Origin Master ,它将依次推入Paws/MasterCodaset/Master ,这使生活变得更轻松。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...