There are two ways to connect with Gitlab
using HTTP and SSH
this guide will let you know about the SSH way and the whole guide is targeting windows os. So what are we waiting for?
Generate an SSH key pair
for ED25519:
ssh-keygen -t ed25519 -C "<comment>"
For 2048-bit RSA:
ssh-keygen -t rsa -b 2048 -C "<comment>"
Follow the instruction and set the passcode and all
After successful execution, SSH key will be generated under c:\users\<username>\.ssh
Add an SSH key to your GitLab account
Run this command in Git Bash:
cat ~/.ssh/id_ed25519.pub
Replace
id_ed25519.pub
with your filename. For example, useid_rsa.pub
for RSA.- Sign in to GitLab.
- On the top bar, in the top right corner, select your avatar.
- Select Preferences.
- On the left sidebar, select SSH Keys.
- In the Key box, paste the contents of your public key. If you manually copied the key, make sure you copy the entire key, which starts with
ssh-ed25519
orssh-rsa
, and may end with a comment. - In the Title box, type a description, like any string will serve the purpose.
- Optional. In the Expires at the box, select an expiration date. In:
- GitLab 13.12 and earlier, the expiration date is informational only. It doesn’t prevent you from using the key. Administrators can view expiration dates and use them for guidance when deleting keys.
- GitLab 14.0 and later, the expiration date is enforced. Administrators can allow expired keys to be used.
- GitLab checks all SSH keys at 02:00 AM UTC every day. It emails an expiration notice for all SSH keys that expire on the current date.
- GitLab checks all SSH keys at 01:00 AM UTC every day. It emails an expiration notice for all SSH keys that are scheduled to expire seven days from now.
- Select Add key
Verify that you can connect
open the terminal or PowerShell and run the command
ssh -T git@gitlab.example.com (for private gitlab)
ssh -T git@gitlab.com
In the final step, open the Visual Studio and try to clone the repository using an ssh URL.
hope this will work for you! If not, please let me know in the comments.