I'm currently trying to figure out how to use GitPython to clone a remote repository with an SSH key that has a passphrase (using Python 3.5.2). The documentation hasn't been very helpful in this regard:
You can also specify per-call custom environments using a new context manager on the Git command, e.g. for using a specific SSH key. The following example works with git starting at v2.3:
ssh_cmd = 'ssh -i id_deployment_key'
with repo.git.custom_environment(GIT_SSH_COMMAND=ssh_cmd):
repo.remotes.origin.fetch()
What I gather from this is that I can load a specific key via the ssh_cmd variable and GitPython will load it, but how does the passphrase get entered? Will the user be prompted? Also, I'm trying to clone from a remote, the code above assumes you've already done that or created a local repository first? Again, it's not very clear, to me at least.
Is what I'm trying to do possible and if so can you provide examples? I'd love to see a simple workflow of:
- Clone a remote repository
- Add changes.
- Commit.
- Push.
All with an SSH key that has a passphrase.
I should also mention I'm doing this on a Windows 7 machine, which pexpect is not compatible with.
GIT_ASKPASS
environmant variable. More information can be found here: git-scm.com/book/en/v2/Git-Internals-Environment-Variables.GIT_SSH
variable, and set it up to provide credentials for you.