Would somebody be allowed to transfer to another branch of the military after the initial 5 years?
Are you asking branch or service? In the Army we consider branches to be parts of the Army (infantry, aviation, cyber,... etc). Services are Army, Air Force, Navy, Marines and Coast Guard. Should we add the Space Force now?
Within the Army it is sometimes possible to change your branch as a Lieutenant, and sometimes it’s planned. A newly commissioned 2LT might be branched quartermaster but detailed to armor for a few years. They would initially serve in armor, then go to the Quartermaster Captain Career Course and switch over to Quartermaster.
Each year Aviation branch normally takes some lieutenants from other branches.
Transferring to another service is not all that uncommon either. Sometimes you actually transfer, but most times there is a break, even if for a day.
I’ve know Army officers who have transferred to the Air Force (active and reserve) and Coast Guard. The Navy isn’t as common but it happens (a West Point graduate and former Army pilot just took over command of an aircraft carrier). It will probably become more rare for pilots due to the increased ADSO and the age cut off. Sometimes there is a waiver for that, sometimes there isn’t. But I know a bunch of Air Force pilots who started out as Army pilots.
Normally when you do these transfers you have to have enough “age” left to advance. If you are a O-3/4 the Coast Guard would make you revert to an O-2 I believe, but this was to help you as you would need to learn the Coast Guard way of doing things before advancing to O-4 billets.
Also, it sometimes happens after additional schooling such as medical schools or some other skill set a service might Ned. I know Army docs who started out in the Navy, Air Force docs who started out in the Army... you name it.
So yes. It happens. But it’s not something I would count on.