In this paper, we present a systematic design for gear shifting using a hybrid system approach. The longitudinal motion of the vehicle is regulated by a PI-controller that determines the required axle torque. The gear scheduling problem is modeled as a hybrid system and an optimization-based gear shifting strategy is introduced, which guarantees that the propulsion requirements are delivered while minimizing fuel consumption. The resulting dynamics is proved to be stable theoretically. In a case study, we compare our strategy with a standard approach used in the industry and demonstrate the advantages of our design for class 8 trucks.