GitPython and SSH Keys?

前端 未结 5 890
生来不讨喜
生来不讨喜 2020-12-14 02:23

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)

5条回答
  •  孤街浪徒
    2020-12-14 03:00

    I'm on GitPython==3.0.5 and the below worked for me.

    from git import Repo
    from git import Git    
    git_ssh_identity_file = os.path.join(os.getcwd(),'ssh_key.key')
    git_ssh_cmd = 'ssh -i %s' % git_ssh_identity_file
    Repo.clone_from(repo_url, os.path.join(os.getcwd(), repo_name),env=dict(GIT_SSH_COMMAND=git_ssh_cmd))
    

    Using repo.git.custom_environment to set the GIT_SSH_COMMAND won't work for the clone_from function. Reference: https://github.com/gitpython-developers/GitPython/issues/339

提交回复
热议问题