Cloning a Mercurial repository over SSH

59,427

Solution 1

Sounds like hg is not on your path. The Mercurial FAQ mentions possible fixes for this issue: FAQ/CommonProblems.

Add the remotecmd value to your Mercurial configuration by opening ~/.hgrc (or Mercurial.ini on Windows) on your client machine and adding the following:

[ui]
remotecmd = /path/to/hg

where /path/to/hg is the path to the hg command on the remote server.

If you're having problems with your Mercurial configuration, you can use the hg showconfig --debug command to obtain a full list of your Mercurial settings along with the path and line number of the configuration file that defines each configuration value.

Solution 2

You need a double // after hostname i.e.:

hg clone ssh://[email protected]//path/to/projectname projectname

Solution 3

Looks like mercurial isn't in your user's PATH on the remote server.

Solution 4

On webfactional I had to add:

export PATH=$PATH:/home/<user>/bin

to .bashrc to get it to work. (also followed the remotecmd advice above)

Solution 5

You can use Sourcetree, TortoiseHg, Mercurial from the terminal, or any client you like to clone your Mercurial repository. These instructions show you how to clone your repository using Mercurial from the terminal.

  1. From the repository, click + in the global sidebar and select Clone this repository under Get to work.
  2. Copy the clone command (either the SSH format or the HTTPS). If you are using the SSH protocol, ensure your public key is in Bitbucket and loaded on the local system to which you are cloning.
  3. From a terminal window, change to the local directory where you want to clone your repository.
  4. Paste the command you copied from Bitbucket, for example:
    CLONE OVER HTTPS:
    $ hg clone https://[email protected]/teamsinspace/hg-documentation-tests
    CLONE OVER SSH:
    $ hg clone ssh://[email protected]/teamsinspace/hg-documentation-tests
    If the clone was successful, a new sub-directory appears on your local drive.
    This directory has the same name as the Bitbucket repository that you cloned.
    The clone contains the files and metadata that Mercurial requires to maintain the changes you make to the source files.
Share:
59,427
Josh
Author by

Josh

Updated on July 05, 2022

Comments

  • Josh
    Josh almost 2 years

    I'm having some difficulty cloning my mercurial repository over ssh.

    Here's what I have tried:

    hg clone ssh://[email protected]/path/to/projectname projectname
    

    It's giving me this error:

    remote: bash: hg: command not found
    abort: no suitable response from remote hg!
    

    hg is installed on the server, however.

    I was trying to follow the instructions on this website.

  • Josh
    Josh over 13 years
    I followed these directions and added remotecmd = ~/bin/hg to the hgrc file in my project and in my home folder, however it doesnt seem to find that. Adding --remotecmd to the command given in the question works, however. How can I get it so I don't have to type it in every time
  • Richard Cook
    Richard Cook over 13 years
    Put it in your .hgrc configuration file in the [ui] section. See comment in answer.
  • Richard Cook
    Richard Cook over 13 years
    You may have conflicts between your system-wide configuration, your user configuration and your project's configuration. Run hg showconfig --debug to see what your configuration is and where the values are derived from.
  • Richard Cook
    Richard Cook over 13 years
    Have you tried setting remotecmd to the absolute path to hg on your remote machine?
  • Richard Cook
    Richard Cook over 13 years
    Hmm. Do you set any default settings in the [defaults] section of any of your configuration files? It's possible that these might override/interfere with other configuration settings. Try removing any [defaults] that might relate to the clone command etc. and see if that makes any difference. However, it will most likely be easiest to change your bash profile on the remote system to ensure that hg is on the path.
  • Josh
    Josh over 13 years
    I haven't touched the defaults. I tried to change the path in ~/.bash_profile from PATH=$PATH:$HOME/bin to PATH=$PATH:$HOME/bin:/home/jrs0390/bin and PATH=$PATH:$HOME/bin:/home/jrs0390/bin/hg but neither of those worked
  • Richard Cook
    Richard Cook over 13 years
    Try setting your path in .bashrc. Have you played with the PermitUserEnvironment setting in your sshd_config file? This article (serverfault.com/questions/130834/…) discusses various settings and environment variables that might affect your PATH.
  • Richard Cook
    Richard Cook over 13 years
    Glad we figured it out eventually!
  • CenterOrbit
    CenterOrbit over 11 years
    remotecmd = /usr/local/bin/hg was the line I added to get my 'server' a Mac with mercurial to work with a pull request. Worked like a charm.
  • rohtakdev
    rohtakdev over 11 years
    add [ui] remotecmd = /path/to/hg as well use above string for connection
  • Paolo
    Paolo over 11 years
    Adding remotecmd to a local .hgrc fixed the path issue. However, in my particular setup remotecmd introduced another error: remote: conq: invalid command syntax. Just adding the PATH value to .bashrc (on webfaction) was enough and really solved any issue for me.
  • akauppi
    akauppi over 11 years
    I'm doing the same as CenterOrbit (= HomeBrew's location for hg). Likely the problem with @Josh back in 2010 has been the use of ~. Should use absolute path - it's pointing at a remote machine anyway.
  • gavenkoa
    gavenkoa over 10 years
    Why it works only with double // for me? Is this documented?
  • lwho
    lwho over 10 years
    @gavenkoa: Because the first slash is not part of the path, but just the separator between host and path, so with one slash it's just a path relative to the user's home directory. The second slash makes it an absolute path.
  • lwho
    lwho over 10 years
    For one-off usage you can also give the remotecmd option on the command line instead of setting it permanently in .hgrc: hg --config ui.remotecmd=/path/to/hg clone ...
  • Ryu_hayabusa
    Ryu_hayabusa almost 10 years
    hg clone ssh://host://path-to-repo/ ... if you have a configured hostname in ~.ssh/config