Set git config credential.helper cache and timeout via python

TomK tomkcpr at mdevsys.com
Sat Dec 11 21:28:32 EST 2021


Hey All,

I have a set of bash and python scripts that all interact with a remote 
git repository.  While running the scripts, when ever a repo is cloned 
using HTTP and a user/pass combination, that information is stored in 
the .git/config file on disk including the password.  I'm able to issue 
the following commands in git to effectively enable the caching of 
credentials in memory for a predefined amount of time off the linux shell:

git config credential.helper 'cache
git config credential.helper 'cache --timeout=300'

However, what is the best way to do so via Python?  I've read through 
the following to try and make sense of how I could do so:

https://gitpython.readthedocs.io/en/stable/reference.html?highlight=cache#git.index.fun.read_cache
https://pypi.org/project/git-credential-helpers/

But neither means appears to have or be able to do what I'm interested 
in.  I would like to prevent the user and password from being stored on 
disk in any shape or form, including eliminating it from .gitconfig / 
.git/config files.   I keep trying to search in google for possible 
solutions using "python git credential helper" and "git prevent storing 
passwords in git config files"  but google keeps returning results on 
how to store passwords IN .git/config files, which is the exact opposite 
of what I want.  :)

An alternative to the above is to use ssh keys, however I would like to 
know an alternate way that avoids using ssh keys.   Wondering if folks 
here did something similar using python and could provide a bit of 
insight how I could go about doing so?

-- 
Thx,
TK.


More information about the Python-list mailing list