Determine the type of clause you're dealing with. Both "which" and "that" are used to introduce a clause. The type of clause indicates which pronoun is appropriate.
Use "that" in a restrictive context where you point to a well-defined subject. For example, in the sentence "The bike that she bought was stolen." the reader clearly knows what bike was stolen.
Use "which" in nonrestrictive contexts where the subject is not so clearly defined. "Which" is more commonly used to point out a distinctive feature of the subject and is set off between commas, along with the descriptive adjective. In the sentence "The bike, which she bought, was stolen," the reader doesn't know what bike was stolen, just that the stolen bike was bought by her.