Sort branch lines to prevent conflicts