title: How can you specify which ssh key `go get` will use
body: <p>I'm using two different github accounts (personal and work) on the same laptop (running Ubuntu version 20). I need to be able to access private repos from work using the ssh key for my work github account.</p>
  <p>I've made it all work using some neat git config controls, i.e. in my <code>~/.gitconfig</code> file I've put:</p>
  <pre><code>[url &quot;git@github.com:work_account/&quot;]
      insteadOf = https://github.com/work_account/
  [includeIf &quot;gitdir:~/src/github.com/personal_account/&quot;]
      path=~/.gitconfig_personal
  [includeIf &quot;gitdir:~/src/github.com/work_account/&quot;]
      path=~/.gitconfig_work
  </code></pre>
  <p>The personal config contains:</p>
  <pre><code>[user]
  name = Your Name
  email = your.name@gmail.com
  [core]
  sshCommand = ssh -i ~/.ssh/id_rsa
  </code></pre>
  <p>The work config contains:</p>
  <pre><code>[user]
  name = Your Name
  email = your.name@work.com
  signingkey = &lt;ID of GPG key&gt;
  [core]
  sshCommand = ssh -i ~/.ssh/id_ecdsa
  [commit]
  gpgsign = true
  [gpg]
  program = gpg
  </code></pre>
  <p>This all works great for pulling and pushing from github (and signing work commits with a gpg key), but it is failing for <code>go get</code> on private repos. For some bizarre reason <code>go get</code> is trying to use my personal ssh key (<code>~/.ssh/id_rsa</code>) instead of my work ssh key (<code>~/.ssh/id_ecdsa</code>). I've set the <code>GOPRIVATE</code> environment variable, i.e.</p>
  <pre><code>export GOPRIVATE=github.com/work_account/*
  </code></pre>
  <p>The output of go get is like:</p>
  <pre><code>$ go get github.com/work_account/private_repo
  go get github.com/work_account/private_repo: module github.com/work_account/private_repo: git ls-remote -q origin in /home/marc/pkg/mod/cache/vcs/ff3efb332cb48232e5da90ff2073685cbdac4a86e3a47aa11663696f4943637a: exit status 128:
          ERROR: Repository not found.
          fatal: Could not read from remote repository.
  
          Please make sure you have the correct access rights
          and the repository exists.
  </code></pre>
  <p>I can see that my ssh agent has both keys:</p>
  <pre><code>$ ssh-add -l
  521 SHA256:EKvhgg24_blah_bApjLSqX4J7l0 your.name@work.com (ECDSA)
  4096 SHA256:r/qcO94F+ox_blah_JkTiVk+aERk your.name@gmail.com (RSA)
  </code></pre>
  <p>When I remove my personal ssh key (i.e. <code>rm ~/.ssh/id_rsa*</code>) then <code>go get</code> works just fine on the private repo, so I know it is definitely just trying to use the wrong ssh key. For some reason it is ignoring the git config <code>core.sshCommand</code>.</p>