In general relativity, a geodesic generalizes the notion of a "straight line" to curved spacetime. Importantly, the world line of a particle free from all external force is a particular type of geodesic. In other words, a freely moving particle always moves along a geodesic.
In general relativity, gravity is not a force but is instead a curved spacetime geometry where the source of curvature is the stressenergy tensor (representing matter, for instance). Thus, for example, the path of a planet orbiting around a star is the projection of a geodesic of the curved 4D spacetime geometry around the star onto 3D space.
In theories such as special and general relativity, spacetime is treated as a Lorentzian manifold. Geodesics on a Lorentzian manifold fall into three classes according to the sign of the norm of their tangent vector. With a metric signature of (+++) being used,
Note that a geodesic cannot be spacelike at one point and timelike at another.
An ideal particle (ones whose gravitational field and size are ignored) not subject to electromagnetic forces (or the like) will always follow timelike geodesics. Note that not all particles follow geodesics, as they may experience external forces, for example, a charged particle may experience an electric field — in such cases, the worldline of the particle will still be timelike, as the tangent vector at any point of a particle's worldline will always be timelike.
Massless particles like the photon will follow null geodesics. Spacelike geodesics exist. They do not correspond to the path of any physical particle, but in a space that has spacesections orthogonal to a timelike Killing vector a spacelike geodesic (with its affine parameter) within such a space section represents the graph of a tightly stretched, massless filament.
Contents 
A timelike geodesic is a worldline which parallel transports its own tangent vector and maintains the magnitude of its tangent as a constant. If a curve x^{α}(s) has tangent then this can be expressed as
which says that the covariant derivative of the tangent in the direction of the tangent is zero. The above equation can be restated in terms of components of U^{α}:
where
and
The parameter s typically represents time for a timelike curve, or distance for a spacelike curve. This parameter cannot be chosen arbitrarily. Rather, it must be chosen so that the tangent vector dx^{α} / ds has constant magnitude. This is referred to as an affine parametrization. Any two affine parameters are linearly related. That is, if r and s are affine parameters, then there exist constants a and b such that .
A geodesic between two events could also be described as the curve joining those two events which has the maximum possible length in time — for a timelike curve — or the minimum possible length in space — for a spacelike curve. The fourlength of a curve in spacetime is
Then, the EulerLagrange equation,
becomes, after some calculation,
The goal being to extremize the value of
where
such goal can be accomplished by calculating the EulerLagrange equation for f, which is
Substituting the expression of f into the EulerLagrange equation (which extremizes the value of the integral l), gives
Now calculate the derivatives:
This is just one step away from the geodesic equation.
If the parameter s is chosen to be affine, then the right side the above equation vanishes (because U_{ν}U^{ν} is constant). Finally, we have the geodesic equation
The notion of geodesic incompleteness is used in the study of gravitational singularities.
True geodesic motion is an idealization where one assumes the existence of test particles. Although in many cases real matter and energy can be approximated as test particles, situations arise where their appreciable mass (or equivalent thereof) can affect the background gravitational field in which they reside.
This creates problems when performing an exact theoretical description of a gravitational system (for example, in accurately describing the motion of two stars in a binary star system). This leads one to consider the problem of determining to what extent any situation approximates true geodesic motion. In qualitative terms, the problem is solved: the smaller the gravitational field produced by an object compared to the gravitational field it lives in (for example, the Earth's field is tiny in comparison with the Sun's), the closer this object's motion will be geodesic.
As Einstein's field equations determine the geometry of spacetime, it should be possible to determine the geodesics of the spacetime as well. For the case of dust, the problem can be solved by using the Bianchi identities. Many attempts have been made to do the same for other matter distributions.
