In the bottom-up synthesis of graphene nanoribbons (GNRs) from self-assembled linear polymer intermediates, surface-assisted cyclodehydrogenations usually take place on catalytic metal surfaces. Here we demonstrate the formation of GNRs from quasi-freestanding polymers assisted by hole injections from a scanning tunnelling microscope (STM) tip. While catalytic cyclodehydrogenations typically occur in a domino-like conversion process during the thermal annealing, the hole-injection-assisted reactions happen at selective molecular sites controlled by the STM tip. The charge injections lower the cyclodehydrogenation barrier in the catalyst-free formation of graphitic lattices, and the orbital symmetry conservation rules favour hole rather than electron injections for the GNR formation. The created polymer–GNR intraribbon heterostructures have a type-I energy level alignment and strongly localized interfacial states. This finding points to a new route towards controllable synthesis of freestanding graphitic layers, facilitating the design of on-surface reactions for GNR-based structures.