GitPython and SSH Keys?

andreihondrari picture andreihondrari · Feb 3, 2015 · Viewed 18.4k times · Source

How can I use GitPython along with specific SSH Keys?

The documentation isn't very thorough on that subject. The only thing I've tried so far is Repo(path).

Answer

Vijay Katam picture Vijay Katam · Dec 20, 2016

Following worked for me on gitpython==2.1.1

import os
from git import Repo
from git import Git

git_ssh_identity_file = os.path.expanduser('~/.ssh/id_rsa')
git_ssh_cmd = 'ssh -i %s' % git_ssh_identity_file

with Git().custom_environment(GIT_SSH_COMMAND=git_ssh_cmd):
     Repo.clone_from('git@....', '/path', branch='my-branch')