Note: this only works when your cloned repo uses SSH url, e.g.: [email protected]:group/repository.git
Tested in Debian with GitLab
- Generate ssh key for repo and enter another filename (not the default one) for saving the key, e.g: /home/user/.ssh/id_rsa_my_repo
ssh-keygen -o -t rsa -b 4096 -C "[email protected]"
- Upload the public key to the git repository server in the Deploy keys section, and mark it as read-only (as good practice)
cat ~/.ssh/id_rsa_my_repo.pub
- Clone the repository
GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa_my_repo" git clone [email protected]:group/repository.git
- Add the private key to your /repo/.git/config
cd my_repo
git config core.sshCommand "ssh -o IdentitiesOnly=yes -i ~/.ssh/id_rsa_my_repo -F /dev/null"
- Now you can update the code as usual
cd my_repo
git pull