To fix push and pull slow GIT commands, when we are using
SSH keys with the Github, Gitlab and Bitbucket repository services, you need to change the IP version setting used.
I allways use the HTTPS connections of the source codes repository services, especially for the practicality of using services on any machine without the need to create SSH keys to the GIT connection.
However, the connection speed has become a problem, especially after Github and Bitbucket forcing interaction with their repositories through SSH keys.
In recent days, I’ve tried very slow connections by sending new commits by push to Bitbucket, especially using shell, but also using Sourcetree or even Phpstorm.
Sending a commit with only one changed file was taking 50 seconds, even more, about 3 minutes in some cases.
After debug the SSH connection to a Git push command, the result was something similar to the following:
ssh -Tv [email protected] [...] debug1: Connecting to bitbucket.org [2401:1d80:1010::152] port 22. debug1: connect to address 2401:1d80:1010::152 port 22: Operation timed out debug1: Connecting to bitbucket.org [126.96.36.199] port 22. debug1: Connection established. [...]
If you are not tired of IPv6 problems, you have not bumped to your eyes as I it bumped to mine, the problem: my Git installation is trying to use IPv6 instead of IPv4 for data transfer connections.
Fixing slow GIT with SSH at Github and other services
As I said in the previous section, the SSH connection via IPv6 is leading the connection to a time limit, reaching timeout.
Only after the timeout error is issued, then IPv4 is used. This was happening to each git command: commit, git pull or git push.
As a quick solution - even a permanent one, I decided to turn off IPv6 to SSH connections.
To accomplish this, you must open the
/etc/sshd_config file on your Linux Ubuntu or Mint, and add the following lines:
Host * AddressFamily inet
After restarting the session, your SSH connections will use IPv4 by default and the slow transfer data using Git will be resolved.
If you want to disable the use of IPv6 in SSH connections only in some specific servers or services, specify the host as in the following example:
Host bitbucket.org AddressFamily inet
In the above configuration I disabled IPv6 in SSH only for Bitbucket servers.
You can do the same for Github or Gitlab servers, or for any other service that you access using SSH.