Switching between two 12 volt sources
Simply use two diodes, this does the trick automatically.
In this example V1 and Bat are power sources, and +VE will be the output.

Note that if you have a load which has a serious current draw (e.g. over 1A) then the diodes must be sized accordingly, and you have to prepare for some power loss on the diode. (0.7W @ 1A).
This can be solved by using a so-called &quot;ideal-diode&quot; which in fact a FET with very low resistance, plus a proper driver chip called &quot;ideal diode controller&quot;.
This solution scales well, the example below works up to 10A, and basically you can easily get FETs at 50A too, nowadays.

(source: linear.com)