git - 如何同步两个git仓库

标签 git offline-mode

我在不同的 PC 上有两个 git 存储库。我在他们每个人身上都有一些本地的分支机构。我不想将此分支发送到远程服务器,只是将它们保留在本地。那么如何在不使用网络的情况下进行同步呢?我可以只在一台 PC 上压缩存储库并移动到另一台吗?那安全吗?也许我可以以某种方式从每个分支导出最新的更改?

最佳答案

与其制作一个裸克隆,我更喜欢制作一个 bundle (参见“How can I email someone a git repository?”),生成一个文件,更容易复制(例如在 USB 内存棒上)

好处是它确实具有裸存储库的一些特征:您可以从中提取或克隆它,但您只需担心一个文件。

machineB$ git clone /home/me/tmp/file.bundle R2

This will define a remote called "origin" in the resulting repository that lets you fetch and pull from the bundle. The $GIT_DIR/config file in R2 will have an entry like this:

[remote "origin"]
    url = /home/me/tmp/file.bundle
    fetch = refs/heads/*:refs/remotes/origin/*

To update the resulting mine.git repository, you can fetch or pull after replacing the bundle stored at /home/me/tmp/file.bundle with incremental updates.

After working some more in the original repository, you can create an incremental bundle to update the other repository:

machineA$ cd R1
machineA$ git bundle create file.bundle lastR2bundle..master
machineA$ git tag -f lastR2bundle master

You then transfer the bundle to the other machine to replace /home/me/tmp/file.bundle, and pull from it.

machineB$ cd R2
machineB$ git pull

关于git - 如何同步两个git仓库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4860166/

相关文章:

git - 是否可以设置 git merge 进行自动解析? (git rerere)

java - Maven 离线 - mvn-plugins 的问题

android - 如何开发离线优先的原生 Android 应用

google-analytics - 使用文件 ://的站点上的 Google Analytics

swift - Git merge 后 Xcode 无法打开项目

Git svn 克隆 : Is it possible to resume after error Malformed XML: no element found?

git - git(1) 中的 "(1)"是做什么用的?

iphone - github 和 XCode 4.2 问题

apache - 本地主机无法在离线模式下连接?

java - 使用 Java 在 Mac 上启动 Minecraft