Git:推送到多个遥控器 [英] Git: Push to multiple remotes

查看:55
本文介绍了Git:推送到多个遥控器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

:如果您已将多个远程存储库链接到本地​​文件,是否可以同时推送到这两个文件?

Short: If you have linked more than one remote repository to your local files, is there a way to push to both of them?

:由于工作原因,我必须使用gitlab和github远程代码.因此,当我进行一些本地更改时,我想更新两个存储库.

Long: Due to work reasons, I have to use gitlab and github remotes for my code. So as soon as I make some local changes I would like to update both repositories.

我的.git/config文件如下所示

My .git/config file looks like this

[core]
  repositoryformatversion = 0
  filemode = true
  bare = false
  logallrefupdates = true
  ignorecase = true
  precomposeunicode = true
[remote "origin"]
  url = https://github.com/myusername/myproject.git
  fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
  remote = origin
  merge = refs/heads/master
[remote "gitlab"]
  url = https://gitlab.com/myusername/myproject.git
  fetch = +refs/heads/*:refs/remotes/gitlab/*

据我了解, git status 命令仅适用于原始远程服务器,这是真的吗?推拉功能也可以与我的原始遥控器一起使用,不幸的是,我无法使用 git add somefile.txt gitlab

As far as I understand the git status command works only with the origin remote, is this true? Push and pull does work with my origin remote as well, unfortunately, I cannot add stuff to my other remote (gitlab) with git add somefile.txt gitlab

如何将内容推送到gitlab遥控器?

How do i push stuff to my gitlab remote?

推荐答案

如果您需要将本地分支推送到两个遥控器,则可以通过以下方式进行操作:

If you need to push a local branch to both remotes, then do so via:

git push origin master
git push gitlab master
           ^^^ specify the remote to be used here

我一般不认为同时推送到两个遥控器是可取的.如果一次推送成功而另一次失败,该怎么办?这还不清楚.

I don't think in general that pushing to two remotes at the same time is desirable. What should happen if one push succeeds and the other fails? This is not clear.

请注意,大多数Git命令都是 atomic ,这意味着它们会完成,或者根本不会发生.这意味着我们不必担心 git push 最终以部分完整,损坏的状态结束.相反,推送要么按照您的指定发生,要么根本没有发生.

Note that most Git commands are atomic, meaning that they happen to completion, or they do not happen at all. This means that we don't need to worry about about a git push ending up in a partially complete, broken state. Rather, a push either happens as you specified, or it did not happen at all.

这篇关于Git:推送到多个遥控器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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