如何保持两个 git 仓库同步?
我正在托管设施的私人服务器上运行我自己的私人 git 存储库。我将它用于任何我无法开源的私人项目。我使用 github 来完成我所有的开源工作。
我在桌面 ubuntu 机器和 MacBookPro 上进行开发。当我对开发系统进行更改时,我会将更改推送到 colo 中的原点并拉到其他系统。我非常擅长使所有三个系统在很大程度上保持最新状态,主要用于备份和灾难恢复目的。
现在 BitBucket 免费提供私人 git 托管,我正在考虑在那里添加我的项目的克隆。此外,我还可以使用 BitBucket 提供的额外功能,而我的准系统私人 git 服务器不提供这些功能。但是,我想继续在我的托管服务器上保留私有存储库的副本,以实现备份冗余。
所以我有几个问题:
在不更改我的标准开发流程(编辑、添加、提交、推送)的情况下,如何自动将推送到服务器的提交同步到 bitbucket 项目?每当我推送到 git 服务器时,我都希望这些提交能够自动推送到我的 bitbucket 项目。我不想改变我的工作流程,并且希望我的开发客户进行尽可能少的更改。
如果我想使用 bitbucket 作为我的主要 git 存储库,如何将我的项目从我的私有 git 服务器迁移到 bitbucket?
一旦我迁移到 bitbucket,我仍然希望在我的服务器上有另一个备份。如何自动将 bitbucket 的提交推送到我的 git 服务器?这基本上与问题 1 相反。
I'm running my own private git repository on a private server in a colo facility. I use it for any private projects that I cannot open source. I use github for all of my open source work.
I do development on a desktop ubuntu machine and on my MacBookPro. As I make changes on my development systems, I push the changes to the origin in the colo and pull to the other system. I'm pretty good about keeping all three systems up-to-date for the most part, mostly for backup and disaster recovery purposes.
Now that BitBucket is offering private git hosting for free, I'm considering adding a clone of my projects there. Besides, then I could use the extra features provided by BitBucket that my barebones private git server doesn't provide. However, I'd like to continue to keep a copy of the private repos on my colo server as well for backup redundancy.
So I have a few questions:
Without changing my standard development process (edit, add, commit, push), how can I automatically sync commits pushed to my server to a bitbucket project? Any time I push to my git server, I'd like those commits to automatically get pushed to my bitbucket project. I don't want to change my workflow and would like as little changes necessary to my development clients.
If I want to use bitbucket as my primary git repo, how do I migrate my projects from my private git server to bitbucket?
Once I migrate to bitbucket, I'd still like another backup on my server. How can I automatically have commits to bitbucket get pushed to my git server? This is basically the reverse of question 1.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于#1,最简单的解决方案是在远程存储库上使用自动推送到 BitBucket 的挂钩。
对于#2:您只需将 bitbucket 添加为遥控器并推送到它而不是 origin。如果您有任何跟踪分支(检查
.git/config
),请将remote = origin
更改为您用于 bitbucket 的任何名称。另一个解决方案是删除/重命名现有的origin
远程并添加 bitbucket 作为原点。对于#3:执行 git fetch 的 cronjob 可能是最简单的方法。
For #1, the easiest solution is using a hook on your remote repo that automatically pushes to BitBucket.
For #2: You simply add bitbucket as a remote and push to it instead of origin. If you have any tracking branches (check
.git/config
), changeremote = origin
to whatever name you used for bitbucket. Another solution would be removing/renaming your existingorigin
remote and adding bitbucket as origin.For #3: A cronjob executing
git fetch
is probably the easiest way to do this.也许你可以在你的私人服务器上添加一个 git hook 以自动推送到 bitbucket。
在 pro git 书中,有一章是关于 git hooks 的: https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks
Maybe you could add a git hook to your private server to push automatically to bitbucket.
In the pro git book, there is a chapter about git hooks: https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks