I am stuck with a basic understanding of the generalized (and even the ordinary version of) Gauss-Bonnet theorem. For a compact 2-dimensional Riemannian manifold $M$ with boundary $\partial M$, let $K$ be the Gaussian curvature of $M$ and $k\_g$, the geodesic curvature of $\partial M$. Then


$$\int\_M K\;dA+\int\_{\partial M}k\_g\;ds=2\pi\chi(M),$$


where $\chi(M)$ is the Euler characteristic of $M$. My questions are:


1. The Gaussian curvature and the geodesic curvature are functions of the connection that one puts on $M$, and in the standard version of the theorem, we usually put the induced Euclidean connection on the 2-manifold $M$ from its embedding space $\mathbb{R}^3$; whereas, the right hand side of the above equation is a topological invariant of $M$, and, thus, is independent of any connection that we adorn $M$ with. Then the left hand side, as well, should be independent of the connection. How is this invariance with respect to the connection on $M$ is concealed in the left hand side integrals?
2. I have only seen the statement of the generalized Gauss-Bonnet theorem (from the book "From Calculus to Cohomology") and I guess it partially answers my question, but I don't have a clear understanding of its underpinning. The generalized version says that, for any 2$n$-dimensional compact oriented smooth manifold $M$,


$$\int\_M Pf\bigg(\frac{-F^{\nabla}}{2\pi}\bigg)=\chi(M)$$


holds, where $F^\nabla$ is the curvature associated with *any metric connection* on the tangent bundle of $M$. Here, $Pf:\mathfrak{so}\_{2n}\to\mathbb{R}$ is something called the Pfaffian and is defined on the space of skew-symmetric matrices.


So the definition of the Pfaffian must be the answer to my question. So how does the Pfaffian make the left hand side invariant with respect to the connection? Why do we require the evenness of the dimension and orientation of $M$? And finally, why do we require a metric-compatible (perhaps, torsion free) connection in the first place?


A detailed explanation would be much appreciated. I have just started reading on Gauss-Bonnet theorem and I guess my query lies at the heart of the underlying philosophy of this gem theorem of differential topology.


Looking forward to a detailed explanation or references on this particular explanation.


(I think partial answer to my question is in Prof. Bryant's answer to this [A question on Generalized Gauss-Bonnet Theorem](https://mathoverflow.net/questions/84521/a-question-on-generalized-gauss-bonnet-theorem).)



Invariance of Gauss-Bonnet theorem with respect to connection?
If $V$ is an $n$-dimensional real oriented vector bundle on a space $M$, it has a [characteristic class](https://en.wikipedia.org/wiki/Characteristic_class) $e(V) \in H^n(M, \mathbb{Z})$ called the [Euler class](https://en.wikipedia.org/wiki/Euler_class). If now $M$ is a closed oriented smooth manifold and $V$ is its tangent bundle, the Euler class $e(M)$ has the property that


$$\int\_M e(M) = \chi(M).$$


That is, its pairing with the fundamental class $[M] \in H\_n(M, \mathbb{Z})$ (this is where we need that $M$ is closed and oriented) is the Euler characteristic of $M$. I don't know if this result has a name; it's a version of the [Poincaré–Hopf theorem](https://en.wikipedia.org/wiki/Poincar%C3%A9%E2%80%93Hopf_theorem). 


At this point we might as well assume that $M$ is even-dimensional because in odd dimensions the Euler characteristic of a closed oriented manifold is zero (by Poincaré duality, or by a computation involving the Euler class). 


To get Chern-Gauss-Bonnet from here we want to know what the Euler class has to do with the Pfaffian of the curvature of a connection. One answer comes from [Chern-Weil theory](https://en.wikipedia.org/wiki/Chern%E2%80%93Weil_homomorphism), which more general describes how to find de Rham forms representing characteristic classes by writing down various polynomials of the curvature of a connection. The reason these constructions end up being independent of the choice of a connection is that any two connections differ by a $1$-form, and adding a $1$-form to a connection changes the curvature, and these special polynomials of it, by an exact form, hence the de Rham cohomology class of the resulting forms doesn't depend on the choice of connection. 


In the case of oriented manifolds, Chern-Weil theory says that the Euler class results from applying the Pfaffian to the curvature, and this fact combined with the above fact yields Chern-Gauss-Bonnet. This is consistent with a more general prescription for how Chern-Weil theory assigns [Pontryagin classes](https://en.wikipedia.org/wiki/Pontryagin_class): the top Pontryagin class corresponds to the determinant of the curvature, which is the square of the Pfaffian, and the Euler class squares to the top Pontryagin class. 


