When you're at the farmers' market, avoid any bulbs that appear soft or damaged, or are sprouting (if it was a wet spring and summer, the cloves may start to grow right away and split the bulb apart even before harvest). Look for undamaged cloves for long-term storage.
The easiest way to store garlic at home is in mesh bags or loosely woven baskets. Garlic with flexible tops can be made into pretty braids to hang. But garlic with a stiff central stalk—often called hardneck garlic—will shatter if you try to braid it.
Garlic keeps longest when stored at 60 to 65 degrees and in moderate humidity. This is what makes storing fresh garlic throughout the winter so hard: Heated winter homes tend to be very, very dry—so dry that garlic cloves will shrivel up and turn rock-like inside their papery skins after just a month or two (if that ever happens to yours, just toss 'em, skins and all, into your next batch of vegetable stock). One trick is to store garlic under an unglazed clay flowerpot in a cupboard, creating a small humidor without completely cutting off air circulation, which can lead to rot problems.
Lacking storage space for an upside-down flower pot? There are a few other easy ways to store garlic that won't undermine its flavor.
Storing garlic in the crisper drawer of your fridge takes care of the humidity problem. Just be aware that once garlic has been in the cold, it will start sprouting within days after being brought to room temperature (this is why garlic from the store often sprouts). So if you store it this way, keep it in the fridge till just before you're ready to use it. If your garlic does sprout, grow some tasty garlic greens by popping the bulb in a small pot of soil on your windowsill.
Leftover peeled cloves or chopped garlic can be stored for a couple of weeks in the fridge in a small, tightly covered container, but this method is not a good option for long-term storing. The minced garlic you can buy in jars at the supermarket has been acidified to keep it safe and usable for months, but I've never been able to find any tested recipes for safely doing this at home.