basically "wa" refers to someone or something for the first time. like indefinite article a.
kore wa pen desu. = This is a pen.
"ga" refers to someone or something already mentioned. like the.
kore ga sakki watashi ga itta pen desn. = This is the pen which I mentioned just a minute ago.
Of course there are lots of exceptions.