- Clone the SSH repo
git clone git@gitlab.com:YourUsername/YourRepoName.git
(this will copy the repo into a new folder YourRepoName)
2. Alterantively to 1 if you have already copied the HTTPS version of the repo
check which version you have with “git remote -v”
$ git remote -v
origin git@gitlab.com:YourUsername/YourRepoName.git (fetch)
origin git@gitlab.com:YourUsername/YourRepoName.git (push)
if you have the repo that starts with git@… it’s already the SSH version if you have https:// then do following to change it to ssh version:
git remote set-url origin git@gitlab.com:YourUsername/YourRepoName.git
3. Create folders and files that store your public key
$ mkdir .ssh && chmod 700 .ssh
$ touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys
4. Copy you public key to authorized_keys file
Copy it from ~/.ssh/id_rsa.pub (or whichever name you’ve given to it)
5. Have a ssh config file for Gitlab
cat ~/.ssh/config
Host gitlab.com
Preferredauthentications publickey
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes
7. Add your SSH pub key in Gitlab for this project
6. Now you’ll be able to do “git pull” without entering login and password for https version