Skip to content

Instantly share code, notes, and snippets.

@billythedummy
Last active March 12, 2025 19:30
Show Gist options
  • Save billythedummy/3cef0a8817bff7ca57ab33abf48b3771 to your computer and use it in GitHub Desktop.
Save billythedummy/3cef0a8817bff7ca57ab33abf48b3771 to your computer and use it in GitHub Desktop.
Windows git bash is stupid

Problem

Assuming you've installed git with default settings on Windows 10, and you have your ssh keys in ~/.ssh (where ~ expands to something like C:/Users/user) as something like id_rsa and id_rsa.pub, you'll be unable to use the git bash to clone repos with git clone [email protected]:user/project.git. The git bash will always output some error log like

Cloning into 'project'...
\302\226\302\[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

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

Solution

stackoverflow answers suggest adding your key to ssh-agent and changing the SSH config for host github. The most annoying part of this issue is that even after you verify you've done the above 2 steps correctly and that ssh access to github works fine with ssh-agent -l and ssh [email protected], the problem still persists.

It just seems like the git bash is unable to clone repos using ssh directly using git clone for some reason. To clone a remote repo, I have to initialize an empty git repo, add remote as origin, and then pull, i.e.

mkdir project && cd project
git init
git remote add origin [email protected]:user/project.git
git pull origin master

Maybe I'm just missing something obvious but until then, I'm posting this gist to make sure I dont waste 1 hour of my life again the next time I encounter this problem.

@emv001
Copy link

emv001 commented Jan 22, 2024

I had the same problem, just closed the terminal, open a new one and carefully type 'git clone' and righ-click paste 'github url-ssh' and works smoothly.

@thscott's was right, tks a lot.

@chongma
Copy link

chongma commented Mar 12, 2025

@nicolai-work thanks. I must have copied in a bad character like you. Typing it out manually worked. Strangest thing is that I copied it from the dropdown on the repo homepage on github.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment