about"Cannon in C major"

This is generally the case, C G Am Em F C F G

But this is often the case.

Like this G becomes G/B, how should I master it, how do I know when I need to become G/B?

It depends if you want to drop the bass C, B, Am, G and F etc. if you don’t want it then leave it out.

A G major triad is G B D. This is an inversion , or voicing, of that, where the order in ascending pitch is changed to be B D G. Same notes, different sound. G/B is normally described as “G over B” or “G with B in the base”

Similarly, C major is C E G, so C/E is E G C.

You will notice the guitar players here get very focussed on ‘voicing’ because of the mechanics of the guitar and the sounds they want to produce.

By ear. Basic rule is, “if you like the sound better than G, use it”