Clone Git repository in windows using ssh
1 min readMar 31, 2023
Straight-to-point blog!
- open cmd and type
ssh-keygen
it will generate a pair of private and public keys, by default keys take the nameid_rsa
, you can use any name you wish. Press enter! Keys generated and stored in c:/Users/computerName/id_rsa - Now create a new folder with name
.ssh
in c:/Users/computerName and copy those generated keys into this folder - create a new file in this
.ssh
folder with nameconfig
make sure it has no other extension and copy following content into it (will explain below)
# if your repo is on gitlab
Host gitlab.com
Hostname gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/<private key file name, = id_rsa>
# if your repo is on github
Host github.com
Hostname github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/<private key file name, = id_rsa>
suppose your repo ssh clone URL is `git@github.com:coderOne/docs.git` that means your hostname will be the string after @ and till :, in this case github.com
4. Uptil now you have configured your windows system, to use the private keys when ssh clone is attempted. Now only thing remaining is you should add the public keys to your repo server!
in this case id_rsa.pub, copy its contents and add new ssh key in either github or gitlab, wherever your repo is hosted
With these 4 points, you should be able to clone the git repo to your windows system, using cmd only.
Let me know if your use case is not covered!