gh: Refactor code that orders remotes by priority

See corresponding algorithm in hub: https://github.com/github/hub/blob/master/lib/hub/context.rb#L211-L215