How do I continue to use Time Machine backups after switching my hard disk?

From http://simon.heimlicher.com/articles/2012/07/10/time-machine-inherit-backup-using-tmutil

Time Machine uses a unique ID (UUID), which is specific to a volume (i.e. a partition of a disk), to associate the volume with its backup. In OS X releases before 10.7 Lion, when people exchanged their disk or migrated to a different Mac, this feature has made it difficult to get Time Machine to continue adding to the backup history of the previously used disk.

In OS X Lion and now also OS X 10.8 Mountain Lion, there is a nifty new Terminal command called tmutil, which makes this whole drama a breeze.

Here's the command

sudo tmutil associatedisk -a "/Volumes/Macintosh HD" "/Volumes/Time Machine Disk/Backups.backupdb/John Doe's MacBook/Latest/Macintosh HD"

See also How can I use an existing Time Machine backup with my new computer?