Basic uses of the particle ga

As illustrated above, ga is a particle similar to wa but does not carry wa's sense of contrast. This is because wa is what is commonly called a topic marker, while ga marks subjects. This is why you use wa twice in sentences like "I'm going to the park, but my friend isn't." (watashi wa kouen ni iku ga, tomodachi wa ikanai) -- using wa for both you and your friends emphasises them as different topics and marks out what they have done. It's a bit like marking the emphasis in the English sentence like this: Me, I'm going to the park, but my friend, he isn't. ("The Grand Old Duke of York" is a great way to understand wa a bit better. Just think "The grand old duke of York wa (omit he) had ten thousand men". Don't make the mistake of assuming wa works like a pronoun -- Japanese simply does not use pronouns in the same manner as English does. Where English requires the pronoun "he", it's understood from context in Japanese and omitted.)

Roughly speaking, ga is used when introducing new information. It is because of this that ga is used in questions: if you're asking a question, what you're going to be asking about is going to be new information to you. For example:
Dare ga kita ka -- Who came?
Satousan ga kita -- Satou came.
Because the answer is also new information, it takes ga as well. The reason ga is used to introduce new information like is that because it emphasises the information that it marks. Let's demonstrate this with a modified version of the park example above, and give it a disgustingly literal translation:
Watashi ga kouen ni itta -- I am the one who went to the park.

An important feature of ga to remember is that it marks the subject of the following verb, rather than the final verb of the sentence which may have a different subject. This is why we use ga for subjects of relative clauses in Japanese.
(Note: I believe a full explanation of relative clauses is outside the scope of this write up, but to simplify: to make a relative clause, simply stick a sentence ending in a plain form verb in front of the noun. I'll underline the relative clauses to make things clearer.)
Kare ga nusunda saifu wo aketa -- (I) opened the wallet that he stole.
Watashi wa Maakusan ga saifu wo nakushita koto wo shirimasen deshita. Oki no doku desu. -- I didn't know (the fact that) that Mark lost his wallet. That's too bad.
One important thing to remember that you will need to learn if you study Japanese at an intermediate level is that in relative clauses, sometimes ga can be replaced by no. I'm sure that sounds totally bizarre and illogical. Surely no must be a totally different particle from ga! Well, you see, the reason for this lies with Classical Japanese. Back in the olden days, Japanese didn't HAVE a subject marker. However, it did have two particles that marked possession: no and ga. In relative clauses, where you would have ga to mark a subject in Modern Japanese, you could only use a possessive particle in Classical Japanese. To cut a long story short, one of the developments of Classical Japanese was that through its repeated and prolific use in relative clauses, ga became a subject particle. The fact that it can be occasionally replaced by no is one of the many remnants of the old language lingering in Modern Japanese. Ever wondered why the Japanese national anthem is called Kimigayo and not Kiminoyo if it means "the reign OF the emperor"?

Some more uses of ga

You may have noticed that ga appeared in one of the sentences above, but it doesn't function as a subject marker at all. This is another use of ga: it can work a lot like a semicolon does in English when you bring two sentences together. Thinking of ga in this way should help you understand it better than strict definitions such as "ga means 'but'! It also sometimes means 'and'", which can be confusing. When using ga in this manner, the main (terminating) verbs of each sentence you've joined must agree in politeness. It shouldn't be too hard to differentiate between ga the semicolon and ga the subject marker: the former will always come after a verb, and the latter will come after a noun. You can make contrasts with it using this semicolon-like role although it will be relatively mild. Wa will help reinforce contrast.

Ga is also used with potential forms of verbs, because when a verb goes into the potential form, it will always be an intransitive verb. As intransitive verbs cannot take direct objects, whatever it is that you can (verb) will be the subject. For example:
Haiku wo kaku -- I write haiku.
Haiku ga kakeru -- I can write haiku. ("Haiku can be written")