A complete continuum mechanical theory for granular media, including explicit expressions for the energy current and the entropy production, is derived and explained. Its underlying notion is: granular media are elastic when at rest, but turn transiently elastic when the grains are agitatedsuch as by tapping or shearing. The theory includes the true temperature as a variable, and employs in addition a granular temperature to quantify the extent of agitation. A free energy expression is provided that contains the full jamming phase diagram, in the space spanned by pressure, shear stress, density and granular temperature. We refer to the theory as GSH, for granular solid hydrodynamics. In the static limit, it reduces to granular elasticity, shown previously to yield realistic static stress distributions. For steady-state deformations, it is equivalent to hypoplasticity, a state-of-the-art engineering model.