3

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:

  1. Clone a remote repository
  2. Add changes.
  3. Commit.
  4. 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.

6
  • 1
    You could try to implement a program to obtain user credentials, and point to it with the GIT_ASKPASS environmant variable. More information can be found here: git-scm.com/book/en/v2/Git-Internals-Environment-Variables.
    – Byron
    Commented Jul 13, 2016 at 11:00
  • Alternatively, you could implement the GIT_SSH variable, and set it up to provide credentials for you.
    – Byron
    Commented Jul 13, 2016 at 11:01
  • Do you happen to have a working example?
    – drohm
    Commented Jul 13, 2016 at 11:49
  • No, however, you can try these out with the git command-line directly, without the need to involve GitPython from the very beginning.
    – Byron
    Commented Jul 13, 2016 at 16:11
  • Setup an ssh-agent and add the ssh key to ssh0agent. Then ssh will not have to prompt for the passphrase. Commented Sep 30, 2016 at 13:32

1 Answer 1

0

I have this same question. It was never answered (4.5 years later). There has to be a way to use GitPython with a ssh key, this is such a basic feature. I do not understand why it is documented.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.