6

I'm seeing the command 'pull' and wondering how that's different from a 'clone'. Both terms seem to imply retrieving code from some remote repository. Is there some subtle distinction here?

Martin Geisler
  • 72,968
  • 25
  • 171
  • 229
tent
  • 1,069
  • 2
  • 9
  • 9
  • 1
    Since you seem to be just starting out with Mercurial, you should probably read through this Stack Overflow question: http://stackoverflow.com/questions/1170338/mercurial-for-beginners-the-definitive-practical-guide You should also read and/or work through the first few chapters of "Mercurial: The Definitive Guide": http://hgbook.red-bean.com/read/ Finally, you might want to create a toy project on http://bitbucket.org/ in order to get some practice working with Mercurial. – las3rjock Sep 09 '09 at 06:03
  • http://hginit.com/ also provides an excellent tutorial. I have all my new employees and interns work through it when they join my team. – JSmitty Jul 22 '13 at 14:35

3 Answers3

19

Use clone when you need to make a new repository based on another. Use pull later to transfer new changesets into the clone. You cannot use clone to fetch just the newest changesets — that is what pull is for. The pull command will compare the two repositories, find the missing changesets in your repository and finally transfer those.

However, you are right that there are similarities between clone and pull: they both transfer history between repositories. If you clone first

hg clone https://www.mercurial-scm.org/repo/hg/

then this has the exact same effect as doing

hg init hg
cd hg
hg pull https://www.mercurial-scm.org/repo/hg/
hg update

You get the exact same history in both cases. The clone command is more convenient, though, since it also edits the .hg/hgrc file for you to setup the default path:

[paths]
default = https://www.mercurial-scm.org/repo/hg/

This is what lets you do hg pull in the repository without specifying a URL. Another advantage of using clone is when you work with repositories on the same disk: hg clone a b will be very fast and cheap in terms of disk space since b will share the history with a. This is done using hardlinks and works on all platforms (Windows, Linux, Mac).

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Martin Geisler
  • 72,968
  • 25
  • 171
  • 229
11

hg clone is how you make a local copy of a remote repository. The Subversion equivalent is svn checkout.

hg pull pulls changes from another repository. hg update applies those changes to the local repository. hg pull -u is equivalent to hg pull; hg update. The Subversion equivalent to hg pull -u is svn update.

las3rjock
  • 8,612
  • 1
  • 31
  • 33
2

clone creates a new repository as a copy of an existing repository.

pull imports all changesets (not already present) from another repository into an existing repository.

wierob
  • 4,299
  • 1
  • 26
  • 27