How do I move a private Mercurial repository to a central server?
Asked Answered
E

2

12

I’m just getting started with Mercurial, and I’ve read Joel Spolsky’s Hg Init tutorial, which I liked.

I’m wondering: let’s say I have a private repository and I work on it for about a month. Then I decide I want to centralize it or make it public, like on bitbucket.org. I want to retain all the history.

The intuitive thing would be to use hg clone, but according to the docs:

The location of the source is added to the new repository's .hg/hgrc file, as the default to be used for future pulls.

I don’t think this is what I’d want, since the source is my local, private repository, and the destination is the public server. I don’t want the public server trying to pull from my private repository in the future thinking it’s the central one. I hope this makes sense.

Do I have to tweak the .hg/hgrc file on the server manually? Am I approaching this correctly?

Eula answered 23/6, 2010 at 20:47 Comment(2)
Ned had your answer, but FWIW you can use clone to create a new repository elsewhere if your destination is a ssh:// URL. If you're talking to the server over http:// then you need to 'hg init' on the server and then 'hg push' from local. The setting of the source as the default for pulls is mostly irrelevant on a push-clone since you'll probably never 'pull' on that remote repo -- only push to it. If you do find yourself pulling on the remote repo man 'you can change the defaults in the [paths] section of the .hgrc.Rancourt
Excellent points - thanks, Ry4an. I see what you mean about the irrelevance of the default pull location on the server.Eula
T
18

BitBucket's help says it's as easy as making an empty repo on BitBucket, then pushing to it:

... create a new empty repository via the "Create repository" page. We will assume that this repository is named blonk and is to be found on http://bitbucket.org/jespern/blonk.

Now, just push to it:

  $ cd ~/Work/blonk # our existing hg repository
  $ hg push http://bitbucket.org/jespern/blonk
  ...

Done!

You can edit .hg/hgrc in your repository to include the default path to Bitbucket:

  $ cat .hg/hgrc
  [paths]
  default = http://bitbucket.org/jespern/blonk

Now you can simply enter hg push and hg pull without having to specify the full URL.

Tedtedd answered 23/6, 2010 at 21:9 Comment(0)
S
4

Doing this operation using 'hg push', as described, is probably the best way to do this, overall.

However in other circumstances it might be convenient, or reassuring, to note that all of the Hg state is contained within the .hg directory, and so simply moving this directory is enough to move the repository.

For example, if you have ssh access to a machine at example.com, you can tar (or zip) up your .hg directory in the 'private' repository, unpack it in, say, ~/repo/foo on the remote machine (thus creating a directory ~/repo/foo/.hg there), and then simply clone this:

$ hg clone ssh://example.com/repo/foo

This does have a slight back-door feel to it, I agree. However, there's nothing really under-the-hood happening here, and no editing of configuration files is necessary. When I do this, I find it less confusing than the 'proper' way.

Sims answered 24/6, 2010 at 10:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.