Git incredibly slow on MacOS - Solution

Lorenzo Sinisi bio photo By Lorenzo Sinisi Comment

I was setting up git on my Mac and I needed to use different SSH keys to accesss different git servers (bitbucket, github) when I noticed that git (any of his operations, took at least 4 seconds). After some research I found out how to fix this issue.

SSH was checking for IPv6 addresses as well as IPv4 addresses, and is hanging until its search times out.

My git config looked like that:

Host hostname-api.github.com
    Hostname github.com
    IdentityFile ~/.ssh/id_rsa-api

Host bitbucket.org.personal
 HostName bitbucket.org
 IdentityFile ~/.ssh/personal_bitbucket

The solution was simple:

Host hostname-api.github.com
    Hostname github.com
    IdentityFile ~/.ssh/id_rsa-api
    AddressFamily inet

Host bitbucket.org.personal
 HostName bitbucket.org
 IdentityFile ~/.ssh/personal_bitbucket
 AddressFamily inet

This solved the issue and now git is as fast as it used to be.

comments powered by Disqus