1

I can clone my repo from github using ssh, but can't fetch or push. I'm using an ssh config with a host entry, named gh-personal, that points to github.com and provides my pubkey.

Furthermore, the usual debugging technique, setting GIT_SSH_COMMAND to "ssh -v," causes the fetches and pushes to WORK.

The clone works:

$ git clone git@gh-personal:dgentry/myDotfiles 
Cloning into 'myDotfiles'...
remote: Enumerating objects: . . . .
Resolving deltas: 100% (3570/3570), done.

The fetch immediately after fails:

$ cd myDotfiles/
$ git fetch
ssh: Could not resolve hostname gh-personal: Temporary failure in name resolution
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Set GIT_SSH_COMMAND in an attempt at debugging, and it works:

$ GIT_SSH_COMMAND="ssh" git fetch
$ # This works

All I can figure is that git is using some kind of internal ssh by default, and that ssh isn't looking up my .ssh/config entry for gh-personal.

(There's more weirdness. If I clone the repo into a directory whose name doesn't match the repo name, fetch/push works normally.)

And, for reference, here's the ~/.ssh/config entry for gh-personal:

Host gh-personal
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519_github
  IdentitiesOnly yes
  AddKeysToAgent yes

Does anyone know how to make this work always?

  • 1
    Consider setting `core.sshCommand` (with `git config --global`), but yeah, it's weird that `git clone` would work at all then. Also consider running with whatever system-call-tracing facility you have, which may help you find out which ssh Git is actually running each time. – torek Mar 20 '22 at 02:32

1 Answers1

1

Check if you have any environment variable related to SSH, by typing set.
And if your PATH references the another ssh before the Git one.

Note the URL can be gh-personal:dgentry/myDotfiles, no need for git@, since the User is part of your gh-personal entry in your ~/.ssh/config.

To be safe, make sure you are testing this with the latest Git version you can upgrade to.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Yes, no SSH env vars, just the .ssh/config. And PATH has only the one ssh, same priority as git: ```$ which git; which ssh``` produces ```/usr/bin/git /usr/bin/ssh``` – Some Guy on the Internet Aug 05 '22 at 20:09
  • Also, thanks for the tip about the URL -- I use that all the time now. – Some Guy on the Internet Aug 05 '22 at 20:14
  • 1
    @SomeGuyontheInternet Do you still have the issue? What version of Git are you using? On which OS? Is it a git bash session on Windows? – VonC Aug 05 '22 at 20:22
  • Yes, I never got this working the way I expect, but it's working well enough either just leaving GIT_SSH_COMMAND set, or using @torek's suggestion they made in a comment. This is on Ubuntu 20.04 and 22.04 with the latest ubuntu git packages. I'll give git bash on Windows a try too. – Some Guy on the Internet Aug 05 '22 at 20:33