“That” and “which” are two of the four most common relative pronouns in English (along with “who” and “whom”).
That is used to introduce restrictive relative clauses—those that give essential information about the noun or noun phrase they modify (e.g., “Book the flight that leaves at 7 a.m.”). Restrictive clauses are not set off by commas.
Which is used to introduce nonrestrictive relative clauses—those that give nonessential details about the noun or noun phrase they modify (e.g., “My assistant booked the earliest flight, which leaves at 7 a.m.”). Nonrestrictive clauses are set off by commas.
In British English, “which” can also be used (without commas) in restrictive clauses. However, in American English, “which” is only used in nonrestrictive clauses.