Which or That
You use that for a defining clause and which for a non-defining clause. An easier way to think about is if your sentence is referring to a specific item then you are probably safe using which. If your sentence is less precise and the reader cannot determine what you mean without the information that comes after the word then you need to use that. If your sentence would be factually incorrect without the information contained in the clause then you must use that. You also need to use a comma after the word which.
Here are a couple examples:
"I need the hammer that is in the garage."
"I need the big sledgehammer, which is in the garage."
You can also think of the information contained in the nonrestrictive clause following which as extra information. People would still know how to find the correct hammer if you said, "I need the big sledgehammer." The garage information is an extra detail in the second sentence. In the first sentence the defining clause suggests there is more than one hammer and hammer has no describing adjectives. The garage location is essential to the sentence, so we must use that.
Grammarly writes in its explanation that which is "as disposable as a sandwich bag." That is a good explanation. Which is used when the clause contains disposable information.
English Language 101 does an excellent job of explaining which word to use as well as why you need to use it. The difference between essential and nonessential is very well explained to help you understand. Take a look:
Here's another explanation from Dr. Clare Lynch. She says use which for incidental information and that for essential information.
Finally, here is an explanation from Grammar to Go using pictures and cut-out words.