首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >能用一个命令推送到所有的git遥控器吗?

能用一个命令推送到所有的git遥控器吗?
EN

Stack Overflow用户
提问于 2011-04-26 11:19:50
回答 7查看 44.9K关注 0票数 227

而不是做:

代码语言:javascript
复制
git push origin --all && git push nodester --all && git push duostack --all

有没有办法只用一个命令就能做到这一点呢?

谢谢:)

EN

回答 7

Stack Overflow用户

回答已采纳

发布于 2013-09-07 22:27:04

要将所有分支推送到所有远程数据库:

代码语言:javascript
复制
git remote | xargs -L1 git push --all

或者,如果您想要将特定分支推送到所有远程:

master替换为您要推送的分支。

代码语言:javascript
复制
git remote | xargs -L1 -I R git push R master

(额外的)为命令创建一个git别名:

代码语言:javascript
复制
git config --global alias.pushall '!git remote | xargs -L1 git push --all'

现在,运行git pushall会将所有分支推送到所有远程。

票数 299
EN

Stack Overflow用户

发布于 2011-04-26 11:34:19

使用多个指向其名称的存储库URL创建一个all remote:

代码语言:javascript
复制
git remote add all origin-host:path/proj.git
git remote set-url --add all nodester-host:path/proj.git
git remote set-url --add all duostack-host:path/proj.git

然后就是git push all --all

这是它在.git/config中的外观

代码语言:javascript
复制
  [remote "all"]
  url = origin-host:path/proj.git
  url = nodester-host:path/proj.git
  url = duostack-host:path/proj.git
票数 317
EN

Stack Overflow用户

发布于 2015-07-15 15:37:46

如果您希望始终推送到repo1、repo2和repo3,但始终仅从repo1拉取,请将远程‘源’设置为

代码语言:javascript
复制
[remote "origin"]
    url = https://exampleuser@example.com/path/to/repo1
    pushurl = https://exampleuser@example.com/path/to/repo1
    pushurl = https://exampleuser@example.com/path/to/repo2
    pushurl = https://exampleuser@example.com/path/to/repo3
    fetch = +refs/heads/*:refs/remotes/origin/*

在命令行配置:

代码语言:javascript
复制
$ git remote add origin https://exampleuser@example.com/path/to/repo1
$ git remote set-url --push --add origin https://exampleuser@example.com/path/to/repo1
$ git remote set-url --push --add origin https://exampleuser@example.com/path/to/repo2
$ git remote set-url --push --add origin https://exampleuser@example.com/path/to/repo3

如果您只想从repo1拉取,但推送到特定分支specialBranchrepo1repo2

代码语言:javascript
复制
[remote "origin"]
    url = ssh://git@aaa.xxx.com:7999/yyy/repo1.git
    fetch = +refs/heads/*:refs/remotes/origin/*
    ...
[remote "specialRemote"]
    url = ssh://git@aaa.xxx.com:7999/yyy/repo1.git
    pushurl = ssh://git@aaa.xxx.com:7999/yyy/repo1.git
    pushurl = ssh://git@aaa.xxx.com:7999/yyy/repo2.git
    fetch = +refs/heads/*:refs/remotes/origin/*
    ...
[branch "specialBranch"]
    remote = origin
    pushRemote = specialRemote
    ...

参见https://git-scm.com/docs/git-config#git-config-branchltnamegtremote

票数 107
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5785549

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档