How can I run git push/pull commands with SSH verbose mode?
Asked Answered
P

2

95

If I run "git push" with the GIT_TRACE=2 environment variable, I get the following:

09:25:28.098743 git.c:349               trace: built-in: git 'push' 'origin' 'master'
09:25:28.100261 run-command.c:341       trace: run_command: 'ssh' '[email protected]' 'git-receive-pack '\''kevinburke/letter.git'\'''

Which is great except sometimes I get this error:

fatal: Could not read from remote repository.

I only get it intermittently so I'm not sure what's going on. I know ssh has a verbose mode:

 -v      Verbose mode. Causes ssh to print debugging messages about its progress. 
         This is helpful in debugging connection, authentication, and configuration
         problems.  Multiple -v options increase the verbosity.  The maximum is 3.

It would be great if I could get git to run that ssh command with -vvv turned on. Is there a way to enable this with environment variables or with config settings?

Parallel answered 19/8, 2014 at 16:28 Comment(0)
S
50

Put this in your ~/.ssh/config file:

Host <git-server-FQDN> LogLevel (QUIET|FATAL|ERROR|INFO|VERBOSE|DEBUG|DEBUG1|DEBUG2|DEBUG3)

Subsequent git commands that interact with the server should produce desired debug output.

Slapup answered 19/8, 2014 at 18:6 Comment(1)
This doesn't help if you are trying to debug issues with which ssh key is being used. It is better to use the answer from @Stieglitz (e.g. GIT_SSH_COMMAND="ssh -v" git ... ).Polis
S
141

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 <REPO_SSH>

you can also pass -vvv for even more verbose level:

GIT_SSH_COMMAND="ssh -vvv" git clone <REPO_SSH>

(as seen here https://askubuntu.com/a/620985/975188)

note that you can also run this with other git commands, such as git push, git fetch etc.

From Git version 2.10.0, you can even configure this per repo or globally:

git config core.sshCommand "ssh -v"
git pull
git push
Stieglitz answered 16/3, 2016 at 14:27 Comment(2)
For older git versions (1.8 or before) I posted a recipe here: https://mcmap.net/q/12679/-how-can-i-debug-git-git-shell-related-problemsSidwell
Issue popped up suddenly using "git version 2.43.0.windows.1" as a VSCode plugin. Setting core.sshCommand (first to "ssh -vv" and then to plain "ssh") seemed to fix it.Camlet
S
50

Put this in your ~/.ssh/config file:

Host <git-server-FQDN> LogLevel (QUIET|FATAL|ERROR|INFO|VERBOSE|DEBUG|DEBUG1|DEBUG2|DEBUG3)

Subsequent git commands that interact with the server should produce desired debug output.

Slapup answered 19/8, 2014 at 18:6 Comment(1)
This doesn't help if you are trying to debug issues with which ssh key is being used. It is better to use the answer from @Stieglitz (e.g. GIT_SSH_COMMAND="ssh -v" git ... ).Polis

© 2022 - 2024 — McMap. All rights reserved.