2

For some reason, my console hangs if I try to run any ssh command. For example:

ssh user@server date will hang,

ssh -f user@server date works.

If I want to include the -f argument in a git remote URL, how would I do so? Right now I have:

git remote add origin ssh://user@server/home/user/repo/mine.git but if I try to push/pull from it, it hangs. I would like to add the -f argument to this URL because I suspect it will solve the problem.

How do I tell git to use the -f argument when calling ssh?

1 Answer 1

4

From the fine manual for git(1) we find

   GIT_SSH, GIT_SSH_COMMAND
       If either of these environment variables is set then git fetch and
       git push will use the specified command instead of ssh when they
       need to connect to a remote system. The command will be given
       exactly two or four arguments: the username@host (or just host)
       from the URL and the shell command to execute on that remote
       system, optionally preceded by -p (literally) and the port from the
       URL when it specifies something other than the default SSH port.

       $GIT_SSH_COMMAND takes precedence over $GIT_SSH, and is interpreted
       by the shell, which allows additional arguments to be included.
       $GIT_SSH on the other hand must be just the path to a program
       (which can be a wrapper shell script, if additional arguments are
       needed).

So therefore the simplest via shell interpretation is

GIT_SSH_COMMAND="ssh -f" git push ...

or a full wrapper via GIT_SSH.

3
  • How do I know if git is using the environmental variable? If I do GIT_SSH_COMMAND="ssh -f" git push origin master it still hangs, so I don't know if the -f was the source of the original problem or not. If I do GIT_SSH_COMMAND="ssh adslkfjalskdf -asfd -adsf" git push origin master I don't get an error, so it seems like git is not using the GIT_SSH_COMMAND variable. Mar 10, 2017 at 18:36
  • A straightforward test of GIT_SSH_COMMAND="ssh -v -v -v" git push ... shows the verbose output from SSH.
    – thrig
    Mar 10, 2017 at 18:40
  • Interesting, I get prompted for my password (like always), but it hangs with no verbose output when doing GIT_SSH_COMMAND="ssh -v -v -v" git push origin master Mar 10, 2017 at 18:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .