To add more to TheLethalCarrot's answer, there is the case of a Tie pilot deserting the Empire after the destruction of Alderaan.
Enrolling at the Imperial Academy together to become fighter pilots for the glorious Empire is nothing less than a dream come true for the both of them. But Thane sours on the dream when he sees firsthand the horrific tactics the Empire uses to maintain its ironclad rule.
Bitter and disillusioned, Thane joins the fledgling Rebellion—putting Ciena in an unbearable position to choose between her loyalty to the Empire and her love for the man she's known since childhood.
Wookieepedia, Star Wars Lost Stars
In legends, desertions and betrayals are a more common occurrence, such as the story of CT-5539 appearing in Darth Vader and the Cry of Shadows, ex-Clone Trooper from the previous war that entered the Imperial Army as a Stormtrooper. Working directly under Vader, he will end his career by leaving the battlefield while in deployment.
Malsuum noticed that Vader was not just killing the resistance fighters, but indiscriminately targeted unarmed civilians as well. Greatly shaken by this realization, he came to doubt the righteousness of what he was doing and whether he had been wrong to trust Vader.
In an attempt to put a stop to further bloodshed, he followed Vader into the hospital, and tried to force the enemy wounded to bow down to Lord Vader, but they stood defiantly. When Vader started executing them, Malsuum called for him to stop, and Vader paused. The clone then dropped his blaster and walked away.
Wookieepedia, CT-5539