We present the epitaxial growth of Mg-containing Ag film on p-type GaN using domain matching epitaxy. No epitaxial growth was found in the as-deposited Ag film, but it changed to epitaxial growth as Mg atoms were added into Ag film. This is due to the fact that Mg atoms were preferentially bonded to O ones, which played a role in shrinking the surrounded Ag lattice from 4.0871 to 4.0858. In addition to that, the volume expansion induced by Mg-O chemical bonding moves the Ag atoms to the site where they are energetically most stable at the Ag/GaN interface, resulting in strong adhesion between Ag films and GaN substrate. As a result, nine domains of the (111)-oriented Ag layer (2.558 nm) are matched with eight domains of the (0001) GaN layer (2.551 nm). This arrangement has the lowest domain mismatch of 8.9%, resulting in the epitaxial growth of the (111) Ag film with the lowest surface energy. Consequently, the Mg-containing Ag film shows better thermal stability, resulting in the suppression of Ag agglomeration.