Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep two git repos synchronized?

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:

  1. 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.

  2. If I want to use bitbucket as my primary git repo, how do I migrate my projects from my private git server to bitbucket?

  3. 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.

like image 826
Tauren Avatar asked Oct 05 '11 09:10

Tauren


2 Answers

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), change remote = origin to whatever name you used for bitbucket. Another solution would be removing/renaming your existing origin remote and adding bitbucket as origin.

For #3: A cronjob executing git fetch is probably the easiest way to do this.

like image 200
ThiefMaster Avatar answered Sep 25 '22 14:09

ThiefMaster


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

like image 36
hellectronic Avatar answered Sep 25 '22 14:09

hellectronic