How to clone repository to a remote server/repository with Mercurial

29,988

Solution 1

You'll want to check out the publishing repositories wiki page to get into web interfaces and access controls, but at it's most basic you can do something like this:

hg clone yourlocalrepo ssh://you@server//home/you/repo

That clones your local repo to a remote location of your choosing. Note that there are two double slashes in that URL.

You can't create a remote repo like that using http://, only ssh://. If all you have is http to hgweb.cgi you can 'hg init' an empty repo on the server and then hg push to it.

Solution 2

If your "official" repositories are served up by an HTTP server, and you want to create a repo in the central location based on a local machine's repo, here's one way. You need admin rights on the central server to do this.

e.g. I'm developing on windows, and my central repository is running on linux and served by lighttpd per the official guide. The server's central repo directory is /var/hg/repos/, owned by the user/group www-data. My local machine's IP is 10.1.10.100, and the repository I want to clone is named foo.

  1. On the local machine, open a command prompt into the repository directory and type hg serve. This runs the local hg web server, which will allow the server to pull from it.
  2. ssh into the central repo server, logging in as a user with sudo rights to www-data.
  3. cd /var/hg/repos
  4. sudo -u www-data hg clone http://10.1.10.100 foo

Solution 3

For those that come later and don't want to bother about the hassles of ssh for pushing changes to a server built to host repos, you can just init on the server, and then push as you do every other repo.

# on server:
cd repos/
mkdir myrepo
cd myrepo
hg init
cd ..
chown -R apache:apache myrepo

cd ..
vim hgweb.config

# change [paths]
[paths]
myrepo = /path/to/myrepo



# on your machine

# make sure you've configured hgrc correctly
[paths]
default = http://server/hg/repos/myrepo

hg push

# ???

# profit
Share:
29,988

Related videos on Youtube

Maya Tzadik
Author by

Maya Tzadik

Updated on July 09, 2022

Comments

  • Maya Tzadik
    Maya Tzadik almost 2 years

    Found myself quite confused today about this.

    I create a blank repository locally(hg init), cloned it to working copy, added some code, commited and pushed it(to local repo obviously).

    Now I need to share that repository with others. There is a server that has mercurial on it, how do I clone my repository to a remote one such that other developers can access it and pull/push code from/to it?

  • Ry4an Brase
    Ry4an Brase about 14 years
    they can just clone from ssh://you@server//home/you/repo if they're allowed to read from your homedir. If you're not okay with that you can set up an area to which you can both read and write.
  • Warren  P
    Warren P about 13 years
    +1 for documenting the usual technique these days... I am sick of the usual technique, so I plan to write a cgi (web page) in python to do the hg clone command for you, from any authorized host.
  • Warren  P
    Warren P about 13 years
    Not a bad idea to be turned into a cgi helper-web-page, either. Create first on the server, clone down the empty one and you're all set up for a centralized workflow.