Skip to content

Instantly share code, notes, and snippets.

@billythedummy
Last active January 22, 2024 06:11
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 git@github.com:user/project.git. The git bash will always output some error log like

Cloning into 'project'...
\302\226\302\226git@github.com: 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 git@github.com, 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 git@github.com: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.

@sentientmachin3
Copy link

sentientmachin3 commented Apr 27, 2021

Bro, I'm literally having the same issue. I confirm git bash is stupid af.

@nicolai-work
Copy link

I'm not exactly sure what did it, but typing in the command

git remote add origin git@github.com:user/project.git

instead of copy-pasting it from the browser seems to have worked.

@thscott
Copy link

thscott commented Apr 19, 2023

I just hit this, and it's due to using Ctrl+Shift+v (muscle memory from linux), which in git bash inserts a "Start of Guarded Area" control character. This is the \302\226 sequence.

You can change git bash options to allow that shortcut for pasting by right clicking on the header and in Options/Keys checking "Ctrl+Shift+letter shortcuts".

See here, here, and here.

@schlagercollin
Copy link

I feel like I should be able to upvote a Gist. Thanks for pointing this out.

Also, @thscott's suggestion on how to fix for the future worked quite nicely. Thanks!

@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.

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