简体   繁体   English

当中央git仓库(GitHub / BitBucket)不可用时如何同步git仓库

[英]How to sync git repositories when central git repo (GitHub/BitBucket) is not available

Normally I push my git-changes from my development machine to BitBucket. 通常,我将自己的git-changes从开发机器推送到BitBucket。 This triggers a webhook to my other machine, which initiates a pull from BitBucket. 这会触发到我的另一台计算机的Webhook,并从BitBucket启动拉取。

[my machine]
   \
    +---1.push--> [bitbucket] <---3.pull------+
                       \                       \
                        +--2.webhook--> [other machine]

However, it is possible for BitBucket to not be available sometimes . 但是, 有时 BitBucket可能不可用 So I also want to be able to push my changes to the other machine directly. 因此,我还希望能够将更改直接推送到另一台计算机。 My git protocol I use to sync with BitBucket is SSH, and I also have an SSH connection to my other machine. 我用来与BitBucket同步的git协议是SSH,并且我也有到其他计算机的SSH连接。

So this is what I want to accomplish. 这就是我想要完成的。

[my machine]
   \
    +---push--> [other machine]

The command to push I use is: 我使用的推送命令是:

git push ssh://USERNAME@SSH_SERVER_NAME/path/to/remote/repository

When there's nothing to sync, I get the message Everything up-to-date . 当没有任何要同步的消息时,我会收到消息“ Everything up-to-date OK, nice. 好很好 But when there is new commit to push, I get an error message (removed some lines for brevity). 但是,当有新的提交要推送时,我收到一条错误消息(为简洁起见,删除了一些行)。

! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'ssh://USERNAME@SSH_SERVER_NAME/path/to/remote/repository'

Someone suggested to switch branches, but I'm unsure if I'm doing the right thing here. 有人建议切换分支,但是我不确定我在这里做对了吗。 Switching branches sound weird, because BitBucket doesn't switch branches either, so why should I do this? 切换分支听起来很奇怪,因为BitBucket也不切换分支,所以为什么要这样做呢?

The questions are: 问题是:

  1. How do I push a change, skipping my normal BitBucket workflow? 如何跳过正常的BitBucket工作流程来进行更改?
  2. Can BitBucket catch up later with the changes? BitBucket以后可以跟上变化吗? I a pull/push from both machines enough to restore the "normal" workflow? 我从两台机器上拉/推足以恢复“正常”工作流程?

You are pushing to a non bare repo, git issues this warning just to prevent a silent modification of the master branch on [other machine] , while someone is possibly working on it. 您要推送到非裸仓库,git发出此警告只是为了防止有人在进行操作时对[other machine]上的master分支进行无提示的修改。

"Switch branch" means : go on [other machine] , and tell your live repo that you are not currently working on the master branch. “ Switch branch”的意思是:继续使用[other machine] ,并告诉您的实时仓库您当前不在master分支上工作。


Here are some other ways to transmit the commit : 这是其他传输提交的方法:

  • go on [other machine] and pull from [my machine] 继续[other machine]并从[my machine] 拉出
  • create a bare repo on [other machine] , push from [my machine] to this bare repo, then on [other machine] pull locally from this bare repo [other machine]上创建一个裸仓库,从[my machine]推送到该裸仓库,然后在[other machine]从该裸仓库本地拉

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

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