简短:有没有办法让git repo推送到远程回购列表(而不是单个"来源")?
长:当我在多台计算机上开发一个应用程序时,我经常遇到这种情况,它有不同的连接 - 比如在运输途中是笔记本电脑,在我在某个位置时是电脑"A",另一台是"B"在另一个.此外,笔记本电脑可能只与"A"或"B"连接,有时两者兼而有之.
我想要的是让git始终"拉"并"推"到它当前可以连接的所有计算机上,这样就可以更轻松地从一台机器跳到另一台机器并继续无缝工作.
ELL*_*BLE 781
现代版本的git!不再需要手动执行此操作!请参阅下面的Malvineous的解决方案.
转载于此:
git remote set-url origin --push --add <a remote>
git remote set-url origin --push --add <another remote>
Run Code Online (Sandbox Code Playgroud)
这一点我已经使用了很长一段时间没有不良后果,并由Linus Torvalds在git邮件列表上提出建议.
araqnid的解决方案是将代码放入存储库的合适解决方案......但是,当你像我一样,有多个等效的权威上游(我将一些更重要的项目克隆到私有上游,GitHub和Codaset),它每天都要将变化推向每一个人,这可能是一种痛苦.
长话短说,git remote add所有你的遥控器单独...然后git config -e添加一个合并遥控器.假设你有这个存储库config:
[remote "GitHub"]
url = git@github.com:elliottcable/Paws.o.git
fetch = +refs/heads/*:refs/remotes/GitHub/*
[branch "Master"]
remote = GitHub
merge = refs/heads/Master
[remote "Codaset"]
url = git@codaset.com:elliottcable/paws-o.git
fetch = +refs/heads/*:refs/remotes/Codaset/*
[remote "Paws"]
url = git@github.com:Paws/Paws.o.git
fetch = +refs/heads/*:refs/remotes/Paws/*
Run Code Online (Sandbox Code Playgroud)
...创建一个合并远程的"Paws"和"Codaset",我可毕竟那些添加以下内容:
[remote "Origin"]
url = git@github.com:Paws/Paws.o.git
url = git@codaset.com:elliottcable/paws-o.git
Run Code Online (Sandbox Code Playgroud)
一旦我完成了这项工作,当我完成这项任务时git push Origin Master,它将推动两者Paws/Master并Codaset/Master顺序完成,让生活变得更轻松.
ara*_*nid 483
您可以使用以下git remote命令配置多个远程存储库:
git remote add alt alt-machine:/path/to/repo
Run Code Online (Sandbox Code Playgroud)
要从所有已配置的远程数据库获取并更新跟踪分支,但不要合并到HEAD,请执行以下操作:
git remote update
Run Code Online (Sandbox Code Playgroud)
如果它当前没有连接到其中一个遥控器,则需要时间或抛出错误,然后继续下一个.您必须从获取的存储库或者挑选中手动合并,具体取决于您希望如何组织收集更改.
要从alt获取主分支并将其拉入当前头部,请执行以下操作:
git pull alt master
Run Code Online (Sandbox Code Playgroud)
所以事实上git pull它几乎是简写git pull origin HEAD(实际上它在配置文件中查找以确定这一点,但你明白了).
要推送更新,您必须手动对每个仓库执行此操作.我认为,推动设计时考虑了中央存储库工作流程.
Mal*_*ous 256
最新版本的git(截至2012年10月)允许您从命令行执行此操作:
git remote set-url origin --push --add user1@repo1
git remote set-url origin --push --add user2@repo2
git remote -v
Run Code Online (Sandbox Code Playgroud)
然后git push将推送到user1 @ repo1,然后推送到user2 @ repo2.git push如果你也希望能够git push从他们那里离开,请不要理会.
Non*_*biz 31
我将这些别名添加到〜/ .bashrc中:
alias pushall='for i in `git remote`; do git push $i; done;'
alias pullall='for i in `git remote`; do git pull $i; done;'
Run Code Online (Sandbox Code Playgroud)
Fel*_*peC 23
您可以添加遥控器:
git remote add a urla
git remote add b urlb
Run Code Online (Sandbox Code Playgroud)
然后更新所有repos做:
git remote update
Run Code Online (Sandbox Code Playgroud)
tro*_*oex 15
这是我在.gitconfig别名部分中使用bash脚本的示例
[alias]
pushall = "!f(){ for i in `git remote`; do git push $i; done; };f"
Run Code Online (Sandbox Code Playgroud)
s.h*_*sam 14
2023 年更新
\n如果您想同时推送多个遥控器,您可能对 git 非常了解。我们在 git 中将远程存储库称为遥控器。将更改推送到遥控器将是通常开发周期的一部分。
\n有时,您可能需要将更改推送到多个遥控器,例如 GitHub、bitbucket 等。为此,您可以按照给定的说明进行操作。
\n您可以使用以下命令列出所有可用的遥控器。
\ngit remote -v\nRun Code Online (Sandbox Code Playgroud)\n假设您尚未配置任何(其他)远程。您可以使用 git 远程来完成此操作。
\ngit remote add remote_name remote_url\nRun Code Online (Sandbox Code Playgroud)\n例子:
\ngit remote add github https//github.com/path/to/repo\nRun Code Online (Sandbox Code Playgroud)\n通常,我们通过默认来源寻址远程名称来推送更改,例如git push origin. 您可以配置多个遥控器组并给它们命名。因此,您可以通过引用该名称来推送所有这些遥控器。
您可以使用 git remote 或 git config 命令或编辑配置文件来添加多个遥控器。
\n由于git可以对多个遥控器进行分组,因此您可以按照以下任意一种方式配置多个遥控器同时推送(不需要全部)。
\n您可以使用 git remote 将多个远程 URL 设置为单个远程。
\n如果您还没有\xe2\x80\x99 名为“all”的远程,请使用创建它git remote add,然后使用git remote set-url --add将新URL 添加到现有远程。
git remote add all <remote URL>\nRun Code Online (Sandbox Code Playgroud)\n然后
\ngit remote set-url --add all <another remote URL>\nRun Code Online (Sandbox Code Playgroud)\n您可以使用 交叉检查添加的新遥控器git remote -v。
(或者)
\n该git config命令用于配置git参数。它将.git/config根据给定的输入编辑文件。
git config --add remote.all.url https//domain.com/repo.git\ngit config --add remote.all.url ssh://user@host/repos/repo.git\nRun Code Online (Sandbox Code Playgroud)\n注意不带--add选项的命令将替换现有的远程 URL。您可以在 验证更新的配置.git/config。
(或者)
\n.git/config 如果您知道配置格式,请编辑文件以添加远程和多个远程 URL。
现在,您可以通过引用分配了多个远程 URL 的远程名称来同时推送多个远程。
\ngit push all master\nRun Code Online (Sandbox Code Playgroud)\n您始终可以推送到多个远程存储库,而无需使用正式的 bash 语法对它们进行分组。
\ngit push server master && git push github master\nRun Code Online (Sandbox Code Playgroud)\n
这个答案与之前的答案不同,因为它避免了--push在git remoteset-url命令中不必要和不对称地使用该选项。这样,两个 URL 的配置都是对称的。对于持怀疑态度的混帐配置如图长相不同的用与不用这个选项。cat ./.git/config
git clone git@github.com:myuser/myrepo.git
Run Code Online (Sandbox Code Playgroud)
git remote set-url --add origin git@gitlab.com:myuser/myrepo.git
Run Code Online (Sandbox Code Playgroud)
push:$ git remote -v
origin git@github.com:myuser/myrepo.git (fetch)
origin git@github.com:myuser/myrepo.git (push)
origin git@gitlab.com:myuser/myrepo.git (push)
$ git config --local --get-regexp ^remote\..+\.url$
remote.origin.url git@github.com:myuser/myrepo.git
remote.origin.url git@gitlab.com:myuser/myrepo.git
Run Code Online (Sandbox Code Playgroud)
git push
Run Code Online (Sandbox Code Playgroud)
要删除添加的 URL:
git remote set-url --delete origin git@gitlab.com:myuser/myrepo.git
Run Code Online (Sandbox Code Playgroud)
小智 7
我在.git congfig文件中向远程"origin"添加了两个单独的pushurl.当我运行git push origin "branchName"然后它将运行并推送到每个URL.不确定是否有更简单的方法来实现这一点,但这适用于我自己推送到Github源代码并同时推送到My.visualStudio源代码.
[remote "origin"]
url = "Main Repo URL"
fetch = +refs/heads/*:refs/remotes/origin/*
pushurl = "repo1 URL"
pushurl = "reop2 URl"
Run Code Online (Sandbox Code Playgroud)
我想在 VSO/TFS 中工作,然后在准备好后公开推送到 GitHub。在私有 VSO 中创建的初始存储库。当需要添加到 GitHub 时,我做了:
git remote add mygithubrepo https://github.com/jhealy/kinect2.git
git push -f mygithubrepo master
Run Code Online (Sandbox Code Playgroud)
像冠军一样工作......
要进行完整性检查,请发出“git remote -v”以列出与项目关联的存储库。
C:\dev\kinect\vso-repo-k2work\FaceNSkinWPF>git remote -v
githubrepo https://github.com/jhealy/kinect2.git (fetch)
githubrepo https://github.com/jhealy/kinect2.git (push)
origin https://devfish.visualstudio.com/DefaultCollection/_git/Kinect2Work (fetch)
origin https://devfish.visualstudio.com/DefaultCollection/_git/Kinect2Work (push)
Run Code Online (Sandbox Code Playgroud)
简单的方法,对我有用...希望这对某人有帮助。