Breck Yunits <> writes:

> It would be very helpful if you could specify the path to the private
> key to use for ssh remotes just like in ssh.

You could add a support for the "remote.<name>.sshIdentityFile"
configuration variable, i.e.

        [remote "origin"]
                url =
                sshIdentityFile = ~/.ssh/id_for_example_com

and then teach the codepath that leads to connect.c::git_connect()
to pass it down, and add "-o 'IdentityFile %s'" to the command line
that invokes "ssh".

But you would need the same number of configuration as you have
remotes that need such custom identity files, which happens to be
the same number of entries you would normally configure with the
standard ~/.ssh/config file, so I do not think it is worth it.

If the only thing you are interested in supporting is a one-shot
invocation, i.e. giving which identity file to use from the command
line when you run either "git push" or "git fetch", I suspect that
you could play with GIT_SSH environment variable, e.g.

    GIT_SSH_IDENTITY_FILE=$HOME/.ssh/id_for_example_com git push

and do something ugly like the attached, I suppose.

It also crossed my mind that you could (ab)use the credential helper
framework and ask it to return not the password but the identity
filename, and pass it down the callchain to git_connect(), but again
you will have to teach the credential helper as many settings as you
would need to make in ~/.ssh/config anyway, so I find it dubious how
it would be a win.

 connect.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/connect.c b/connect.c
index a80ebd3..87b7ceb 100644
--- a/connect.c
+++ b/connect.c
@@ -623,9 +623,10 @@ struct child_process *git_connect(int fd[2], const char 
                die("command line too long");
        conn->in = conn->out = -1;
-       conn->argv = arg = xcalloc(7, sizeof(*arg));
+       conn->argv = arg = xcalloc(20, sizeof(*arg));
        if (protocol == PROTO_SSH) {
                const char *ssh = getenv("GIT_SSH");
+               const char *ssh_ident = getenv("GIT_SSH_IDENTITY_FILE");
                int putty = ssh && strcasestr(ssh, "plink");
                if (!ssh) ssh = "ssh";
@@ -637,6 +638,12 @@ struct child_process *git_connect(int fd[2], const char 
                        *arg++ = putty ? "-P" : "-p";
                        *arg++ = port;
+               if (ssh_ident) {
+                       char *ident_arg = xmalloc(strlen(ssh_ident) + 50);
+                       sprintf(ident_arg, "IdentityFile %s", ssh_ident);
+                       *arg++ = "-o";
+                       *arg++ = ident_arg;
+               }
                *arg++ = host;
        else {
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to
More majordomo info at

Reply via email to