Einstein--Hilbert action

Recall in Newton-Cartan gravity we have 2ϕ=4πGNρ and so a mass distribution ρ determines a geometry in spacetime (a connection) such that

Ric00=4πGNρ.

This prompted Einstein to postulate that the relativistic field equations for the Lorentzian metric g of spacetime ought to be something like

Ricab=8πGNTab.

However, this equation suffers from a problem: it should be (aT)ab=0 for energy-momentum conservation, but in general (aRic)ab0. Einstein tried to argue this problem away, but it turns out that these equations are fundamentally wrong and cannot be upheld, and we are to obtain a new set of field equations.

Hilbert was a variation principle specialist and had the brilliant idea to say "The right-hand side of the gravitational field equations come from an action (see the definition of energy-momentum tensor), so why don’t we try and obtain the left-hand side from an action too?" He decided to work through the simplest actions he could until he obtained one that worked. His final result was the following:

SH[g]:=MgR=MgRicabgab.

The variation of this action with respect to g is Gab:=Rab12gabR.
In addition to the gravitational action, you also need an action for the matter fields. The specific form of the matter action depends on the nature of the matter or energy you are considering. For a scalar field ϕ(t,x), the action Smatter might look like this:

Smatter[ϕ,g]=M(12gμνμϕνϕV(ϕ))gd4x

The total action Stotal of the system is the sum of the Einstein-Hilbert action and the matter action:

Stotal=SEH[g]+Smatter[ϕ,g]

The first term governs the dynamics of the spacetime geometry, while the second term governs the dynamics of the matter field, both of which are coupled through the metric gμν.

To derive the equations of motion for both the metric gμν and the matter field ϕ, you vary the total action with respect to each field:

The Einstein field equations tells me how the Einstein curvature results from a matter distribution. This determines a Riemann curvature for spacetime. But then, matter moves along spacetime, and it gets redistributed, according to the geodesics of the metric. And this new matter distribution creates a new curvature.