Skip to content

pulling from private repo #1489

Description

@rogelioamancisidor

I can clone from a private repo by specifying the path to he ssh key, like this:

git_dir = "git@github.com:user_id/repo_name.git"
save_at = './'
Repo.clone_from(git_dir, save_at, env={"GIT_SSH_COMMAND": 'ssh -o StrictHostKeyChecking=no  -i ./my_path/mykey'})

However, I this code cannot pull from the same private repo

repo = Repo(save_at)
ssh_cmd =  'ssh -o StrictHostKeyChecking=no  -i ./my_path/mykey'}
with repo.git.custom_environment(GIT_SSH_COMMAND=ssh_cmd):
    repo.remotes.origin.pull('master')

and throws the error

File "/usr/local/lib/python3.10/site-packages/git/remote.py", line 910, in pull
    res = self._get_fetch_info_from_stderr(proc, progress,
  File "/usr/local/lib/python3.10/site-packages/git/remote.py", line 750, in _get_fetch_info_from_stderr
    proc.wait(stderr=stderr_text)
  File "/usr/local/lib/python3.10/site-packages/git/cmd.py", line 502, in wait
    raise GitCommandError(remove_password_if_present(self.args), status, errstr)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(1)
  cmdline: git pull -v origin master
  stderr: 'fatal: Could not read from remote repository.'

What am I missing here?

Activity

  1. Byron commented on Sep 7, 2022

    @Byron
    Member

    With the GIT_PYTHON_TRACE=1 and GIT_TRACE=1 environment variable set, you should see which commands are actually invoked and maybe get to the bottom of it.

    Generally the approach of using GIT_SSH_COMMAND should work with custom_environment.

  2. rogelioamancisidor commented on Sep 7, 2022

    @rogelioamancisidor
    Author

    Can I set the environmental variables in the python code? My code runs in a kubernetes container so it will be to much of a trouble to declare those env variables in a secret so I can hopefully debug what is going on.

    I updated the error message. Do you know what does GitCommandError(remove_password_if_present(self.args), status, errstr) mean?

  3. added theissue type on Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions