Really verbose way to test Git connection over SSH?

When using GIT, I have problems with using GIT over SSH, and since it works just fine both from work, and at home with a different modem, it's obviously my home modem that is acting up. I have no problems connecting over HTTP.

So, I'm assuming it is an SSH problem, but I'm no expert at using it directly. Is there any command I can run which sets up a "test" connection, and lets me know exactly when and where along the line the problem occurs?

Pretty much all "larger" commands (such as fetch, clone, or push with much data) from git (even when run with -v) just "hang" in the middle of connecting remotely with no indication as to why they have stopped, so they are of no use.

Is there any way I can get more details on what is happening in the SSH connection?


Solution 1:

Environment variable

From Git version 2.3.0, you can use the environment variable GIT_SSH_COMMAND and pass the -v verbose argument like this:

GIT_SSH_COMMAND="ssh -v" git clone example

To be extra verbose, make it -vvv:

GIT_SSH_COMMAND="ssh -vvv" git clone example

Git config

From Git version 2.10.0, which will in Ubuntu 17.04's repos, you can save this configuration globally, or per repo as in this example:

git config core.sshCommand "ssh -vvv"
git pull

Solution 2:

I had a similar problem. For debugging I added a line in my ssh_config. Here is how I've done it:

git remote -v

There you will find a line like this:

origin  [email protected]:me/test.git (fetch)
origin  [email protected]:me/test.git (push)

In this case the host is github.com. Now you can add a Host-Entry in you ssh config:

vim ~/.ssh/config

And add:

Host github.com
    LogLevel DEBUG3

On using git operations, you should get plenty of debug messages, now. To get lesser debug messages, try using DEBUG1

For GIT versions >= 2.3.0 see the answer from @Flimm for a smarter solution.