aubreypwd

Aubrey Portwood

A Quick Guide to using Mercurial (Mercurial for Dudes)

| Permalink

Okay, so you downloaded Mercurial and you want to start using it with a friend to modify a WordPress theme.

First, login via FTP (or whatever) and download the code to your own computer, let’s say /home/user/my_code.

Now this is where you are going to make all your code changes, in /home/user/my_code.

First, you want to tell Mercurial to make this folder a repo, using,

cd /home/user/my_code
hg init

Now the folder is going to be tracked by Mercurial. At this point Mercurial is not tracking any files though. No, Mercurial will not just track all files in the folder.

To tell Mercurial what to track you will have to tell Mercurial what files are in the folder using,

hg addremove

This command will tell Mercurial to go through the entire directory and find all files in the folder and track them. The first time you do this it will add all files in the folder and track changes to them.

Now you can go and make changes to these files, add new files, and delete files.

At this point you’ve made changes, added files, and deleted/renamed some files. You’ve changed the program to do something, and you want to update Mercurial on your progress. You do so using,

hg addremove
hg commit -m "it now does something"

So, we’ve seen the hg addremove before, hg commit tells Mercurial to take a snapshot of the code and give it a unique ID (called an SHA) you can refer to later. The -m “…” part tells Mercurial the details of the snapshot, which you can see using,

hg log

Now, you feel you are done and you want to put the code on the central repository on BitBucket.org. Let’s do that for our first time. It’s easy, just do,

hg push https://bitbucket.org/user/my_code

It will ask you for username/password stuff and hit enter. Done.

Okay, now your buddy wants to make a change to your code, so he,

hg clone https://bitbucket.org/user/my_code

This will copy the same code you just pushed to his own computer. He now has a repo of his own with your code you just pushed earlier. Now, he goes in, makes some changes, and boom is done and does the following (you get it by now, right?)

hg addremove
hg commit -m "buddy did something: blows bubbles now"
hg push https://bitbucket.org/user/my_code

Okay, great now he’s gone and changed your code. But, he broke something, IDIOT! Okay, so now you want to go fix it. But wait, your repo’s are out of sync now! Do you just push your code…..NO!

Sure, that would fix it, but he also created a feature that made your website blow bubbles, trust me, you want to keep that. So, you haven’t made any changes to your code. You’re smart, and you know your buddy is messing with things too. So, what you do is….

hg pull https://bitbucket.org/user/my_code

This pulls all the new changes from the central repository on BitBucket.org, including your buddies awesome bubble-blowing feature and his stupid screw up! Okay, so can you go off changing code?….No!

First, you need to tell your own repo to include those changes in your code, so you can edit it. Do so by doing….

hg up

This tells your repo to upgrade to the latest changes, now your own repo should look exactly like your buddies repo and the central repository.

Now, go fix that stupid screw up, changes some code, rename some files, delete some code. But! Don’t forget it blows bubbles now!

Okay, so you’ve fixed it, you’re proud, way to go. Now you want the central repository to have the new fix, to do this we simply push it using,

hg addremove
hg commit -m "fixed buddies screw up, now blows bubbles AND doesn't break"

Okay, just to confuse you more. Let’s say it was Saturday when we fixed the problem. But, on Sunday your buddy decided to add a new feature. Now it makes toast too! So, what he did was,

hg pull https://bitbucket.org/user/my_code
hg up
(change files)
hg addremove
hg commit -m "this thing now makes freakin' toast!"
hg push https://bitbucket.org/user/my_code

Okay, now it’s Monday (hate Monday’s?). You want to put the code on the production website because it blows bubbles and makes toast! Do you just go upload your repo folder to wp-content/themes?…No!

You need to get that toast feature in your own repo…..so we just do,

hg pull https://bitbucket.org/user/my_code
hg up

Okay, you tested  the toast feature on your local machine, and wow he didn’t screw it up this time! Nice job buddy!

Okay, so now you can  get this version of the WordPress theme on your website! Log in via FTP, and just copy your repo (on your computer)

Okay, it’s Tuesday, your starting to find out your buddy is actually pretty good and building features. It now get’s a beer for you, nice! But, you haven’t done anything to your code, but you want to get the new feature on the web! What do you do?

hg pull https://bitbucket.org/user/my_code
hg up

Okay, now log in via FTP and upload the new feature………..

Get it now?