If purchasing new, you will buy a matched set including the pinion shaft in the transmission. By the book, BOTH need to be replaced.
However, I have seen people run mismatched gears without any problems, as the gears are straight cut bevel.
In saying that, when you remove the final drive to do the repair, you may find that the pinion gear inside the transmission is missing some hardfacing & you may need to replace it any ways.....
If the pinion shaft inside the transmission needs doing - the entire transmission needs to be removed.
If the transmission comes out, there is some special tooling required to do the rebuild.
If you are only doing the final drive, you need to set bearing preloads & measure the bevel gear backlash for install to the transmission.
A service manual is mandatory equipment.
**TIP - when you remove the final drive housing from the transmission, there are shims between the two housings - DO NOT drive anything between the flanges to separate them as this WILL damage the shims & they are mighty EXPENSIVE!!!