Git for Windows does not read SSH config with correct git command

I am using git (2.46.0, currently latest version) in Windows 10. I have correctly written config file in ~/.ssh/config (or C:\Users<user_name>.ssh\config):

Host tt
  HostName github.com
  IdentityFile ~/.ssh/id_rsa_xxx
  IdentitiesOnly yes

The problem is, when I run git clone git@tt:<github_user_name>/test3.git, it says that:

Cloning into 'test3'...
ssh: Could not resolve hostname tt: Name or service not known
fatal: Could not read from remote repository.

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

I have read questions like Git for Windows does not read SSH config, but the problem cannot be solved.

Running git config --list gives

diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
http.sslbackend=openssl
http.sslcainfo=D:/Program Files/Git/mingw64/etc/ssl/certs/ca-bundle.crt
core.autocrlf=true
core.fscache=true
core.symlinks=false
pull.rebase=false
credential.helper=manager
credential.https://dev.azure.com.usehttppath=true
init.defaultbranch=master

Running ssh -T git@tt gives

Hi <github_user_name>! You've successfully authenticated, but GitHub does not provide shell access.

How can I solve this problem? Thanks in advance!

Edit:

Running (in powershell) $Env:GIT_TRACE=1, git clone git@tt:<github_user_name>/test3.git gives

09:02:58.739800 exec-cmd.c:243          trace: resolved executable dir: D:/Program Files/Git/mingw64/bin
09:02:58.763535 git.c:472               trace: built-in: git clone git@tt:<github_user_name>/test3.git
Cloning into 'test3'...
09:02:58.838928 run-command.c:667       trace: run_command: unset GIT_DIR; GIT_PROTOCOL=version=2 ssh -o SendEnv=GIT_PROTOCOL git@tt 'git-upload-pack '\''<github_user_name>/test3.git'\'''
09:02:58.838928 run-command.c:928       trace: start_command: ssh -o SendEnv=GIT_PROTOCOL git@tt 'git-upload-pack '\''<github_user_name>/test3.git'\'''
ssh: Could not resolve hostname tt: Name or service not known
fatal: Could not read from remote repository.

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

Running git -c core.sshCommand="ssh -vvv" clone git@tt:<github_user_name>/test3.git gives

09:13:02.388635 exec-cmd.c:243          trace: resolved executable dir: D:/Program Files/Git/mingw64/bin
09:13:02.417159 git.c:472               trace: built-in: git clone git@tt:<github_user_name>/test3.git
Cloning into 'test3'...
09:13:02.480940 run-command.c:667       trace: run_command: unset GIT_CONFIG_PARAMETERS GIT_DIR; GIT_PROTOCOL=version=2 'ssh -vvv' -o SendEnv=GIT_PROTOCOL git@tt 'git-upload-pack '\''<github_user_name>/test3.git'\'''
09:13:02.483484 run-command.c:928       trace: start_command: 'D:/Program Files/Git/usr/bin/sh.exe' -c 'ssh -vvv "$@"' 'ssh -vvv' -o SendEnv=GIT_PROTOCOL git@tt 'git-upload-pack '\''<github_user_name>/test3.git'\'''
OpenSSH_9.8p1, OpenSSL 3.2.2 4 Jun 2024
debug1: Reading configuration data /etc/ssh/ssh_config
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/c/Users/<user_name>/AppData/Roaming/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/c/Users/<user_name>/AppData/Roaming/.ssh/known_hosts2'
debug2: resolving "tt" port 22
debug3: resolve_host: lookup tt:22
ssh: Could not resolve hostname tt: Name or service not known
fatal: Could not read from remote repository.

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

The issue you’re facing seems to be related to Git for Windows not properly recognizing your SSH config file. The problem may stem from the way Git for Windows interprets file paths, especially when working with the SSH configuration file. Here’s a breakdown of steps you can follow to fix it:

1. Check SSH Config Path

Windows paths and Unix-style paths can differ in Git for Windows. Ensure that the path in the IdentityFile directive is in a format Git for Windows can recognize.

Change this:

IdentityFile ~/.ssh/id_rsa_xxx
IdentityFile /c/Users/<user_name>/.ssh/id_rsa_xxx

2. Use Full Path for Git Config File

Git for Windows sometimes has trouble resolving shorthand paths like ~/.ssh/config. Use the full path instead:

Host tt
  HostName github.com
  IdentityFile /c/Users/<user_name>/.ssh/id_rsa_xxx
  IdentitiesOnly yes

3. Check SSH Agent

Ensure that your SSH key is added to the SSH agent. Run these commands in Git Bash or PowerShell:

eval $(ssh-agent -s)
ssh-add ~/.ssh/id_rsa_xxx

4. Use Correct SSH URL

Ensure you’re using the correct format when cloning the repo. The format should be:

git clone git@tt:<github_user_name>/<repo_name>.git

Make sure there are no typos in <github_user_name> or <repo_name>.

5. Test Connection with SSH

Run this command to ensure the SSH configuration is working:

ssh -T git@github.com

It should give you the “You’ve successfully authenticated” message.

6. Check Git Installation

Verify that Git is installed correctly and on the system path. You can do this by running:

where git

This will show where Git is installed.