Is there any condition on a commutative ring $R$ so that the global dimension of $R$ coincides with the supremum of the global dimensions of the localizations $R_{\mathfrak{m}}$ at all maximal ideals $\mathfrak{m}\subset R$? I'm looking (if possible) for conditions which are easy to verify.

This problem is discussed at length in T.Y. Lam's Lectures on Modules and Rings. The hyperlink should take you to the Theorem in question (5.92 in section 5G). The point is that for a commutative noetherian ring $R$ you get the result you wanted and also more:
The proof Lam gives avoids the machinery of Ext, using instead the fact that the global dimension of a commutative noetherian local ring is the injective dimension (also the projective dimension) of its residue field. Note that the noetherian assumption really is necessary. On page 197, Lam points out that B. Osofsky has constructed some interesting examples (he gives details) which I suspect would show this theorem fails without the noetherian hypothesis. 


If one of the localizations isn't regular, then both $R$ and that localization have infinite global dimension, so it's trivially true in that case. So we can reduce to the case that $R$ is regular. Then Spec($R$) can't have irreducible components intersecting. Since the global dimension of a regular local ring is just its dimension, we need to require that all connected components of Spec($R$) have the same dimension. So let's focus on the case when $R$ is a regular domain. We need to know that all maximal ideals have the same height. If we assume that $R$ is a quotient of a polynomial ring over a field, then this true. There are probably counterexamples otherwise. 

