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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With