ssh: Omit port option from ssh command unless specified in remote url by jayong93 · Pull Request #6845 · libgit2/libgit2
Currently, when using GIT_SSH_EXEC feature, libgit2 doen't respect a Port config in ssh config because it always insert -p 22 option to a ssh command if there is no port value in a git remote url (e.g. git@my-custom-domain.org:user/path). I've experienced this for my company's GHE.
One caveat of this implementation is that if you specify port 22 in a remote url despite a different port in ssh config, it will be ignored.
For example, in ~/.ssh/config:
Host my-custom-domain.org
Port 1234
and if you try to fetch or push with a remote url ssh://git@my-custom-domain.org:22/user/path, the port 1234 will be used.
It would be unlikely someone tries to do this though, I guess.
EDITED:
Now -p <port> option is added only when the port is specified in a remote url.