2

I am attempting to write a python script that will run through a specified directory and update all local git repositories in the directory using GitPython. Everything I've written up to this point works and accomplishes the goal, but only if the repository is public.

If it's a private repository, which requires an authorized token, there does not seem to be any way to pull the repository by feeding a token to the function.

Current code:

import git

try: 
    local_directory = '/usr/share/git_repository' # Change me             
    git.cmd.Git(local_directory).pull()
    print("Success! %s is now up to date" % directory)

except git.exc.GitCommandError as e:
    if "Permission denied" in e.stderr:
        print("DOH! You don't have permission!")
    else "Something else went horribly wrong that is totally unrelated to this question."

Has anyone else encountered this problem that knows any way to feed a personal token into this or any other function in GitPython? I'm not finding anything in the documentation.

phd
  • 82,685
  • 13
  • 120
  • 165
  • Please provide a minimum working example that works against a public repository. – merlin2011 Sep 27 '17 at 20:41
  • I have edited the question. I can't provide you a working example of a private repository. You need to have access to a private repository to see what I'm talking about. Essentially, you cannot clone or pull a private repository without a token. This is true when you are using the standard git CLI. –  Sep 27 '17 at 21:25
  • Does this answer your question? [gitpython git authentication using user and password](https://stackoverflow.com/questions/44784828/gitpython-git-authentication-using-user-and-password) – Vaibhav Dhiman Feb 23 '22 at 04:24

0 Answers0