24Captain Rex is in the Rebel Alliance
The history of stormtroopers has always been an issue of debate in Star Wars continuity. Initially introduced as straightforward foot soldiers of the Empire, it was later revealed that stormtroopers were originally clones that fought alongside the Jedi, and had latent programming to wipe out the Jedi Order with
the execution of Order 66.
By the time of the original trilogy there are still some clones in the ranks of stormtroopers, although most of the soldiers have been replaced with conscripts. But not all clones serve the will of the empire. Captain Rex, Captain Gregor, and Commander Wolffe were each able to successfully circumvent the programming that would trigger Order 66, and eventually retired from the Empire, living together on the planet Seelos.
Upon meeting the crew of the Ghost, Captain Rex joins up with the fledgling Rebel Alliance, lending his veteran experience and knowledge of Imperial protocols to the the cause. His ultimate fate hasn’t been revealed, but showrunner Dave Filoni has acknowledged the character’s strikingly similar appearance to a Rebel commando seen on Endor during Return of the Jedi.