Remote Sync

This extension is not distributed with Mercurial.

Author: Ryan Seto



Mercurial Remote Sync (hg-rsync) provides some methods to your working directory in sync with remote files, that exist outside of the repository.

Currently only supports WinSCP.


Configure your .hgrc or mercurial.ini to enable the extension by adding the following lines:

rsync = /path/to/hg-rsync

All of hg-rsync's configuration are set under [rsync].

Here is an example:

script = sync/winscp.txt
path = ssh:// #Optional
cmd = /path/to/winscp.exe #Optional


The script file that will be used by WinSCP.

This can be the relative path from the base directory of your local repository or an absolute path.

See WinSCP's scripting documentation for details on how to write this script.

hg-rsync makes two parameters available from within the script.

  1. The connection portion of the path configuration.

    • ( from the example.)

  2. The path portion of the path configuration.

    • (remote/path/to/sync from the example.)

Here is an example:

option batch on
option confirm off
option transfer automatic
option exclude "readme.txt"
open %1%
cd %2%
synchronize local www/images/upload www/images/upload
synchronize local www/files/upload www/files/upload

This will tell WinSCP to do the following:

  1. Open a connection using the login, host, and port specified in the path.

  2. Change to the directory specified in the path.

  3. Synchronize your several local directories with the remote directories.
  4. Exit.


This is the remote path to the base directory you want to sync from. By default this will be the default path found under the [paths] portion of your hgrc. You can either specify a full ssh:// path or an alias for a path defined under [paths].


By default, hg-rsync will search for WinSCP in the default install directories. If you have WinSCP elsewhere, then specify where the the executible is with this option.


hg rsync [-s SCRIPT] [PATH]

To use hg-rsync, simply run the following command. This will requires that you at least set the script option and have a default path.

    hg rsync


-s SCRIPT, --script SCRIPT



You can add a hook to keep your working directory in sync while you work. If you decide to use a hook, make sure you are configured to sync without having to specify a password.

Here is an example that will sync after you Pull changes.

postincoming.rsync = python:/path/to/


RemoteSyncExtension (last edited 2011-09-25 13:54:27 by YannEMORIN)