10

How do I configure automatic push in Mercurial and Git? Sometimes I forgot to push in a computer, and when I move my location, I'm out of the sync with the good code. Is there a way to mercurial and git do this every hour, for instance?

John John Pichler
  • 4,427
  • 8
  • 43
  • 72
  • 5
    It's worth noting here that it's a better idea to just learn to push. You really don't want to push after every commit. If you do this, you break some of git's best tools -- you cut yourself off from rebase, `commit --amend`, and other great history-editing tools. – Daenyth Oct 01 '10 at 16:14
  • Just noting that our team lead insists on having developer's local repositories mirrored on a server just for the point of having a live backup; they aren't actually part of our day-to-day process. – rvalue Jan 20 '12 at 04:22
  • Open your minds. I use source control even when I'm working alone. And I work on different computers. – John John Pichler Sep 23 '14 at 18:35
  • Just sometimes that is convenient to me use automatic pushing. I turn off later. – John John Pichler Sep 23 '14 at 18:44

2 Answers2

20

With git you can use the post-commit hook to push after each commit. To do this you'll need to add an executable post-commit script in your .git/hooks directory. For e.g.

#!/bin/sh
#
# An example hook script that is called after a successful
# commit is made.
#
# To enable this hook, rename this file to "post-commit".

git push --mirror remote 

Where remote refers to the name of the remote repo that you are pushing to.

You can also setup cron to execute this script every hour if you wish.

Update

Mercurial has hooks too (but of course). Here is the relevant documentation. I haven't used Mercurial so you'll have to work it out yourself.

Manoj Govindan
  • 72,339
  • 21
  • 134
  • 141
9

In mercurial you'd put this in your .hg/hgrc

[hooks]
commit = hg push
Ry4an Brase
  • 78,112
  • 7
  • 148
  • 169