How can I add remote repositories in Mercurial?

MercurialRepositoryHg Paths

Mercurial Problem Overview


I am working with Git repositories in the following way:

  • I have the master repository and several remotes on the different production machines.
  • I am pushing the production code to the remotes and restart the services for the changes to take effect.

I am about to switch from Git to Mercurial and I would like to know ahead how I can achieve something like that.

Mercurial Solutions


Solution 1 - Mercurial

You add entries to the [paths] section of your local clone's .hg/hgrc file. Here's an example of a section that would go in the .hg/hgrc file:

[paths]
remote1 = http://path/to/remote1
remote2 = http://path/to/remote2

You can then use commands like hg push remote1 to send changesets to that repo. If you want that remote repo to update is working directory you'd need to put a changegroup hook in place at that remote location that does an update. That would look something like:

[hooks]
changegroup = hg update 2>&1 > /dev/null && path/to/script/restart-server.sh

Not everyone is a big fan of having remote repos automatically update their working directories on push, and it's certainly not the default.

Solution 2 - Mercurial

if you want to add default path, you have to work with default in your ~project/.hg/hgrc file. As Follows:

[paths]
default = https://path/to/your/repo

Good Luck.

Solution 3 - Mercurial

You could have a look at hg-git GitHub plugin:

hg-git general idea

> adding the ability to push to and pull from a Git server repository from Mercurial. This means you can collaborate on Git based projects from Mercurial, or use a Git server as a collaboration point for a team with developers using both Git and Mercurial.

Note: I haven't tested that tool with the latest versions of Mercurial.

Solution 4 - Mercurial

If you're on Unix and you have Git installed, you can use this bash function to readily add a path to the remotes without a text editor:

add-hg-path() {
    git config -f $(hg root)/.hg/hgrc --add paths.$1 $2
    awk '{$1=$1}1' $(hg root)/.hg/hgrc > /tmp/hgrc.tmp
    mv /tmp/hgrc.tmp $(hg root)/.hg/hgrc
}

Then invoke it with:

$ add-hg-path remote1 https://path.to/remote1

If someone would like to build a Powershell equivalent, I'd like to include that as well. Other potentials improvements include error checking on the parameters and factoring out the call to $(hg root).

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiontoplessView Question on Stackoverflow
Solution 1 - MercurialRy4an BraseView Answer on Stackoverflow
Solution 2 - MercurialAakashView Answer on Stackoverflow
Solution 3 - MercurialVonCView Answer on Stackoverflow
Solution 4 - MercurialJason R. CoombsView Answer on Stackoverflow