That and which have distinct uses.
That introduces a restrictive clause, that is, the information in that clause is essential to the meaning of the sentence. Which introduces a nonrestrictive clause—the information in that clause is not essential to the meaning of the sentence—and therefore should be preceded by a comma. For example, in He supports programs that encourage young people, the “that” clause specifies what kinds of programs he supports. But in She supports Habitat for Humanity, which constructs houses for low-income buyers, the “which” clause adds incidental information—the information is nonessential to the main thrust of the sentence.
IF THE PREVIOUS PARAGRAPH MADE YOUR HEAD SPIN, JUST GO BY THIS: “If you see a which without a comma before it, nine times out of ten it needs to be a that. The one other time, it needs a comma. Your choice, then, is between comma-which and that. Use that whenever you can.” A LITTLE MORE GUIDANCE: “First, if you cannot omit the clause without changing the basic meaning, the clause is restrictive; use that without a comma. Second, if you can omit the clause without changing the basic meaning, the clause is nonrestrictive; use a comma plus which. Third, if you ever find yourself using a which that doesn't follow a comma, it probably needs to be a that.”