Category Archives: Mercurial Tutorial

Mercurial hg pull, hg push and hg update

A small tutorial on using Mercurial as a website repository.

This is a small tutorial on how to use mercurial 1.8.4. as a version control system. If you need information on what a version control system is: check out this link: Version Control.

A few things to note:

Configuring your repository:

  • Make sure to be in the correct directory before you do any commands in mercurial, you may end up making changes you will regret later!
  • My Repository (home repository) is located in “D:\Repositories”.
    • It’s called “Repo_1”, located at “D:\Repositories\Repo_1”.

Hg Pull

  1. At some point we might want to make changes to “Repo_1”. We can pull “Repo_1” from the Mercurial website Repository. “A pull propagates changesets from a “remote” repository (the source) into a local repository (the destination)” (Mercurial Wiki). When one pulls from the “source” repository, only changes that are not in the “home” repository will be added. Hg pulls all the changes, but doesn’t automatically update your working directory with the changes. The changes pulled area called ‘changesets’, and can include files, branches, heads, etc.
  2. Note: If you want to pull you must first have a repository named/initialized in your repository folders.
  3. Notice that if the repository is named correctly and not initialized the command “hg pull” will not work. The repository must be named and initialized for “hg pull” to work.
  4. The commands for “hg init” are below. (hg init initializes the repository)
    cd D:\repositories\hg\repo_1
    hg init
  5. The commands for “hg pull” are below
    cd D:\repositories\hg\repo_1
    hg pull https://mercurial.<your domain>/hg/repo_1
    enter username: <your username>
    enter password: <your password>
  6. If everything went correctly your home repository will have changesets added to it from the source repository.
  7. Keep the command prompt open, we will be using this for “hg update”.

Hg update

  1. Now that we have pulled the changesets of Repo_1 off of the source repository, it is now possible to retrieve the files and folders off of the source repository. We can do this by using the command “Hg update”.
  2. My home repository for Repo_1 has no files contained inside of it.
  3. The source repository has three files on it right now, that I want on the home repository.
  4. My source repository has three files called “Repo_1_text.txt”, “Repo_update_text.txt” and “Other_New_Text.txt”. My goal is to have these files added to my home repository “Repo_1”.
  5. You always want to “hg pull” before we can do an “hg update”. That way, you have the most current repo information. You should still have the command prompt open from the last step. In the command prompt type in the following command.
    hg update
  6. Simple! If everything worked out correctly, the three files from the source repository will be inside your home repository.

Hg Push

  1. Now let’s say we added a couple files to our home repository. These files are called “fox.txt” and “zebra.txt”. We have our current home repository how we like it, now we want to update the source repository to reflect the changes we’ve made. We can do this by “pushing” our changesets to the source repository.
  2. Couple updates, we must run “hg add” to add the “zebra.txt” and “fox.txt” files to our repository. Then we must run “hg commit“. It’s necessary to “commit” before each “push”.
  3. Here is my home repository before the hg push.
  4. Commands for push
    hg add
    hg commit -m "message" --user "username"
    hg push https://mercurial.<yourDomain>/hg/repo_1
  5. This is what the source repository looks like after the push.
Side Note: If you liked/disliked this blog please leave a comment! I want to know what you think!

Posted by on July 22, 2011 in Mercurial, Mercurial Tutorial


Tags: , , , ,