Where should we apply commas in the following sentence?

When you’re sitting in the shade on a rock in the herd trying to do some coursework but Whiskey wants some attention.

When you’re sitting in the shade on a rock in the herd, trying to do some coursework, but Whiskey wants some attention.