The field equations of gravity coupled to electromagnetism and equations of motion of a charged particle are part of the Kaluza–Klein theory where general relativity is extended to five dimensions. These equations can also be obtained if nonholonomic constrains are imposed on the 5-vector of particle’s velocity. Hence, further development of the general relativity theory can be sub-Riemannian (or sub-Lorentzian) geometry. Gauge transformations become a special case of coordinate transformations in both the Kaluza–Klein theory and the nonholonomic model. Sub-Riemannian geodesics are proved to be equations of motion of a charged particle. The Dirac operator can be extended for a 5-dimensional manifold as a first-order differential operator. Since the base manifold in physics contains the electromagnetic gauge group U(1), the eigenvalues of the charge operator are always an integer multiplied by the fundamental electric charge.