I've been wrestling with this problem for quite a while now, and I can't seem to understand what I am allowed to do or not.
Let us consider the following action : $$S = \int \sqrt{-g_{\mu\nu}\frac{dx^{\nu}}{|ds|}\frac{dx^{\mu}}{|ds|}}|ds|$$
Now, I want to show that this gives the famous geodesic equation if we choose $|ds| = d\tau$, the proper time. I know how the proof goes with the variation of S, but I wanted to prove it with the Euler-Lagrange expression, and that is how I arrive to the root of my problem.
I know that if we choose the parameter as stated before, we must have that $$g_{\mu\nu}\frac{dx^{\nu}}{|ds|}\frac{dx^{\mu}}{|ds|} = -1.$$ Obviously, we can't replace that directly in the initial equation for S, otherwise we will have a constant lagrangian. My question is therefore the following : when can I effectively set $g_{\mu\nu}\frac{dx^{\nu}}{|ds|}\frac{dx^{\mu}}{|ds|}$ to be $-1$, without coming up with a wrong result ? Indeed, let me write the steps for the Euler-Lagrange equation :
$$\frac{d}{d\tau}\left(\frac{\partial}{\partial U^{\alpha}}(\sqrt{-g_{\mu\nu}U^{\nu}U^{\mu}}) \right) = \frac{\partial}{\partial x^\alpha}(\sqrt{-g_{\mu\nu}U^{\nu}U^{\mu}})$$
$$\frac{d}{d\tau}\left(\frac{g_{\alpha \nu}U^{\nu}}{\sqrt{M}} \right) = \frac{\partial_{\alpha}g_{\mu\nu}}{2\sqrt{M}}U^{\mu}U^{\nu}$$
With $$U^{\nu} = \frac{dx^{\nu}}{|ds|}$$ and $$M = -g_{\mu\nu}U^{\nu}U^{\mu}.$$
Now, in the above equation, if I set $M = 1$, then I do find the geodesic equation. Let me rephrase the question : why can I set $M = 1$ now? If I had set $M = 1$ before doing any of the $\frac{\partial}{\partial U^\nu}$ or $\frac{\partial}{\partial x^\nu}$ derivatives, I would have gotten a wrong result. Why can I set $M=1$ inside the $\frac{d}{|ds}$ derivative, but not inside the others? I hope I made myself clear!