简体   繁体   English

Git:推送到多个遥控器

[英]Git: Push to multiple remotes

Short : If you have linked more than one remote repository to your local files, is there a way to push to both of them? 简短 :如果您已将多个远程存储库链接到本地​​文件,是否有办法推送到它们?

Long : Due to work reasons, I have to use gitlab and github remotes for my code. Long :由于工作原因,我必须为我的代码使用gitlab和github遥控器。 So as soon as I make some local changes I would like to update both repositories. 因此,只要我进行一些本地更改,我就想更新这两个存储库。

My .git/config file looks like this 我的.git / config文件看起来像这样

[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/*

As far as I understand the git status command works only with the origin remote, is this true? 据我所知, git status命令只适用于origin remote,这是真的吗? 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)与git add somefile.txt gitlab

How do i push stuff to my gitlab remote? 我如何将东西推送到我的gitlab遥控器?

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. 目前尚不清楚。

Note that most Git commands are atomic , meaning that they happen to completion, or they do not happen at all. 请注意,大多数Git命令都是原子的 ,这意味着它们恰好完成,或者它们根本不会发生。 This means that we don't need to worry about about a git push ending up in a partially complete, broken state. 这意味着我们不需要担心git push在部分完整,破碎的状态下结束。 Rather, a push either happens as you specified, or it did not happen at all. 相反,推送要么按照您的指定发生,要么根本不发生。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM