Creating Repositories Over SSH

posted by Steve Losh on October 2, 2009

Let’s say you’ve got a bunch of repositories on another computer somewhere, and you use SSH to push and pull from them.

What if you make a new repository locally and do some work, then want to create that repository on the server? The most common way is to log into the server and create an empty repository first:

$ ssh yourserver
$ cd path/to/repos
$ hg init newrepo
$ logout
$ hg push ssh://yourserver/path/to/repos/newrepos

That works, but it’s a lot of typing. Mercurial has a feature that will help you out: you can use hg clone to create a new repository over ssh:

$ hg clone . ssh://yourserver/path/to/repos/newrepos

Note: You’ll still need to add the new path to .hg/hgrc manually.

You don’t need to log into the server to create a new repository, you can use hg clone to do it.