Local gauge invariance of Dirac Lagrangian Let $$\mathcal{L}  = i \hbar c \overline{\psi} \gamma^{\mu} \partial_{\mu} \psi - mc^2 \overline{\psi} \psi $$ be the Lagrangian density for a free Dirac field. I'm studying particle physics from the book of Griffiths (section 11.3. local gauge invariance).
I want to apply the gauge transformation $$\psi \rightarrow e^{-iq \lambda(x) / \hbar c} \psi. $$ This won't leave the Lagrangian invariant since we pick up an extra term, because $$ \partial_{\mu} \psi \rightarrow e^{-iq \lambda(x) / \hbar c} \bigg[ \partial_{\mu} - \frac{iq}{\hbar c} (\partial_{\mu} \lambda) \bigg] \psi. $$ 
Now Griffiths says that if we replace in the Dirac Lagrangian every derivative $\partial_{\mu}$ with the covariant derivative $$ D_{\mu} = \partial_{\mu} + \frac{iq}{\hbar c} A_{\mu}$$ the transformation $$A_{\mu} \rightarrow A_{\mu} + \partial_{\mu} \lambda $$ will cancel the offending term and leave the Lagrangian invariant. Now I wanted to check if this really works, but in my final calculations I always end up with an extra term. I have $$ \mathcal{L}^{'} = i \hbar c e^{iq \lambda / \hbar c} \overline{\psi} \gamma^{\mu} (\partial_{\mu} + \frac{iq}{\hbar c} A_{\mu}) \big( e^{-iq\lambda / \hbar c} \psi \big) - mc^2 \overline{\psi} \psi. $$ Now I also replace $A_{\mu}$ by $A_{\mu} + \partial_{\mu} \lambda$ . Then I get $$\mathcal{L}^{'} = i \hbar c e^{iq \lambda / \hbar c} \overline{\psi} \gamma^{\mu} \partial_{\mu} \bigg( e^{-iq\lambda / \hbar c} \psi \bigg) - q e^{iq \lambda / \hbar c} \overline{\psi} \gamma^{\mu} \big( A_{\mu} + \partial_{\mu} \lambda \big) \big( e^{-iq\lambda / \hbar c} \psi \big) - mc^2 \psi \overline{\psi}. $$ But if I work this out, I end up with $$\mathcal{L}^{'} = i \hbar c \overline{\psi} \gamma^{\mu} (\partial_{\mu} \psi) - mc^2 \overline{\psi} \psi - q \overline{\psi} \gamma^{\mu} A_{\mu} \psi.  $$ Notice the extra term that shows up. Did I do something wrong here? Would appreciate some help because I want to understand this.
 A: You've misunderstood Griffiths. Replacing 
$$\partial_\mu \to D_\mu$$
is part of a recipe for making a gauge invariant Lagrangian. The subsequent Lagrangian is invariant under the transformations,
$$\psi \rightarrow e^{-iq \lambda(x)} \psi \quad\text{and}\quad A_{\mu} \rightarrow A_{\mu} + \partial_{\mu} \lambda$$
The replacement $\partial_\mu \to D_\mu$ is not part of the gauge transformation.
A: This all makes sense if one uses the language of fiber bundles. But I shall try to avoid it and translate it to a less technical form. What is happening is the following: You have a manifold on which you are doing physics. But in general you do not have global coordinates but you have coordinate patches. These coordinate patches could have areas where they intersect and therefore when when we make a transformation from one set of coordinates to another the physics in the intersection should match. In this case it means the Lagrangian should not change.We are changing from on set of co-ordinates with some transformation. The transformation we use to transform from one coordinate to another is from the lie group  $U(1)$ and is done by $\psi \rightarrow e^{iq\lambda(x)}  \psi$ . Now start off with the following lagrangian:
$$\mathcal{L} = i \hbar c \overline{\psi}\gamma^{\mu}\partial_{\mu} \psi -m^2 c^2 \overline{\psi}\psi $$ What you found out was the phyics did not stay the same when you changed coordinates. This  is unacceptable because physics can't depend on coordinate systems.
So what went wrong? The problem is that our manifold is not locally flat and in fact it has some curvature to it with a rule on how to do parallel transport. Just like in G.R there is a connection that changes how the partial derivative looks like in your case $ \partial_{\mu} \rightarrow \partial_{\mu} - iq \partial_{\mu}(\lambda) $ The extra term is the analog of the Christoffel symbols. 
Now in the second part of the exercise Griffith has already given you the Lagrangian that has the covariant derivative with the right connection one form or to use physics language "gauge field". The Lagrangian has already been modified to reflect the fact that there is curvature. Also the gauge field or connection has to transform appropriately when we change coordinates. It turns out that the general transformation rule is $ A'_{\mu} \rightarrow g A_{\mu}g^{-1} + g^{-1}dg $ where g is an element in some group. For QED which is what you are dealing with $ g = e^{i\lambda(x)} \in U(1) $ . Notice how it gives the right transformation rule for $A_{\mu}$ Griffith gave you. What I am describing is called gauge invariance or gauge symmetry which is a really bad name for coordinate transformation.
The amazing thing is that in order for my Lagrangian to be coordinate invariant on a manifold with curvature it implies that it has to include a coupling of the fermion with the photon hence the extra term you got $q\overline{\psi}\gamma^{\mu}A_{\mu} \psi $. 
The last thing, I have mentioned curvature and you might be wondering what is the analog of the Riemann tensor ; it is $F_{\mu \nu}$ . I have cut a lot of corners but I hope this makes sense.
