The most effective method of producing p -type gallium nitride is currently through incorporation of magnesium. However, such doping leads not only to the desired shallow acceptors but also to the creation of much deeper energy levels. Magnesium-related acceptors have been observed in many optically detected magnetic resonance experiments and their magnetic properties, as characterized by the g values of the holes which they trap, have been found to vary significantly according to the growth conditions and doping levels. The purpose of the present paper is to present a model that accounts for these observations. The model assumes that, in the deep acceptors, the hole is located in an atomic orbital of p character, presumed to be on a nitrogen atom. The orbital degeneracy is partly removed by the wurtzite crystal field and finally by a reduction in local symmetry associated with the relative positions of the magnesium dopant and the nitrogen atom upon which the hole is localized. Further changes in the local crystal field are caused by the presence of nearby defects or by strain. These changes in the crystal field are accompanied by changes in acceptor depth. The approach leads to the correct g values and the correct correlation between the g values and acceptor depth for reasonable choices of the parameters. In the limit that the low symmetry fields become small, the model evolves to one that is consistent with the correct forms of the ground and near-ground Kramers doublets that are observed by other workers in studies of shallow acceptors in material that is not doped with magnesium. Finally, the model is shown to be entirely consistent with a range of acceptor states of different depths being formed by simple substitution of a magnesium ion at a gallium site, rather than by the creation of more complicated defects. The conclusion also highlights the need for the GaN to be of high crystalline quality if effective p -type doping is to be achieved.