Electron spin resonance experiments were performed on Si-doped wurtzite and zinc-blende GaN and Si-doped wurtzite ${\mathrm{Al}}_{x}{\mathrm{Ga}}_{1\ensuremath{-}x}\mathrm{N}$ alloys with $x=0.15,$ 0.32, 0.52, 0.75, and 1. For zinc-blende GaN, an isotropic g factor of 1.9475 is found. The g tensors of the silicon effective mass donor in wurtzite GaN and ${\mathrm{Al}}_{x}{\mathrm{Ga}}_{1\ensuremath{-}x}\mathrm{N}$ alloys are determined experimentally, and for $x<0.38$ are identical within experimental error to tensors observed in unintentionally n-type-doped material. With increasing Al content, the g values increase and the g-tensor anisotropy is reduced. The g values are calculated within a five-band $k\ensuremath{\cdot}p$ model in the cubic approximation. To account for the isotropic g factor of wurtzite AlN, a nonvanishing spin-orbit coupling of the higher ${\ensuremath{\Gamma}}_{5}$ conduction bands of the order of 50 meV is necessary. To describe the anisotropy at lower Al content, a full seven-band $k\ensuremath{\cdot}p$ model for the wurtzite crystal structure is investigated. The model shows that the anisotropy in this material system is also due to coupling to higher conduction bands rather than to valence bands. Additional estimates for the momentum matrix elements and the interband mixing coefficients are discussed.