0

I have a git repository on an internal server and now want to have a scheduled task that automatically pulls changes to my local version. Found the GitPython package, which seems to be exactly what I need, but can't get it to work due to the password protection of the repo.

I have already cloned the repo to my local path (git clone git@LOCAL_IP:/repo/MY_GIT.git .) and will get prompted for the password every time I execute git pull from the command line (fair enough). According to How can I call 'git pull' from within Python?, I then tried exactly this

import git
g = git.cmd.Git(MY_LOCAL_PATH)
g.pull()

and (of course) get an error:

...
git.exc.GitCommandError: Cmd('git') failed due to: exit code(1)
  cmdline: git pull
  stderr: 'Permission denied, please try again.
Permission denied, please try again.
...

Unfortunately, from the many answers around the web dealing with PythoGit, I found none that tells me how I can set the password (I know that you should never ever hardcode passwords, but still...).

phd
  • 82,685
  • 13
  • 120
  • 165
s6hebern
  • 725
  • 9
  • 18
  • Local (on the filesystem, even if it's networked) or remote (i.e. via network)? `MY_LOCAL_PATH` and `LOCAL_IP` isn't helping either to clarify this... – Ulrich Eckhardt Mar 16 '22 at 11:20

1 Answers1

1

You can save credentials within git so that every git client can access them and won't ask the user. See How can I save username and password in Git? for details on how to do that.

SebDieBln
  • 3,303
  • 1
  • 7
  • 21
  • So instead of the `--global` flag I use `--local` to store the credentials only for that repo? Like: `git config --local credential.helper store`, then `git pull` and that's it? – s6hebern Mar 16 '22 at 10:01
  • Yes, that should work. If you aren't asked again for your credentials when you run `git pull` on the command prompt it should also work from GitPython. – SebDieBln Mar 16 '22 at 10:46
  • Unfortunately, it does not work for me. Whatever I try, I'm getting prompted for the PW every time. But this is another question, I'll search around. – s6hebern Mar 16 '22 at 10:59