Reputation: 1188
I'm using the command git config credential.helper 'cache'
so I don't have to input my username and password repeatedly. However, this requires that I set the credentials one time. Is there a way that I can initialize the cache, pipe in the value from an environment variable that will be available at runitme (say $USER
and $PASS
), but not have it store long term?
I don't want to use git config user.name "your username"
and the equivalent password
command because it will try and store the password in plaintext. I basically just want to run in a script
git config credential.helper 'cache'
git config /*set $USER in cache*/
git config /*set $PASS in cache*/
but not sure what the second and third commands would look like, if they exist.
Upvotes: 6
Views: 2767
Reputation: 76569
It is possible to prime the cache by using git credential approve
, as described in the git-credential(1)
manual page, but there's an easier way to do what you want.
The credential helper that you use can be an arbitrary shell script, which can produce the standard format based on the environment. So you could do this:
git config credential.helper '!f() { printf "%s\n" "username=$USER" "password=$PASS"; };f'
Of course, in many environments, it is easier and more secure to use a passwordless SSH key, but some situations, such as container building, don't permit that in a secure way, so the example I gave above can be helpful.
Upvotes: 10