Kent Milder
Kent Milder

Reputation: 83

How to set git cache --timeout for long period?

Here Git push requires username and password I read how pushing/pulling to/from github do not enter login/passowrd any time running git command in command line.

I found next :

git config --global credential.helper 'cache --timeout 7200'

After enabling credential caching, it will be cached for 7200 seconds (2 hour).

I decided that 2 hours too small and tried to set cach 200 hours with command :

git config --global credential.helper 'cache --timeout 7200000'

I have Ubuntu 18 both at my local server and on remote server.

But when I run github next day(I think 10-12 hours passed) it did not work.

Does this cache option has some hours restrictions or what is the problem ?

Thanks!

Upvotes: 6

Views: 8801

Answers (1)

Matthew Rasa
Matthew Rasa

Reputation: 700

Based on your comment, it seems that caching works correctly on your server (that is rarely restarted), but not your laptop (which is frequently restarted).

The documentation for git-credential-cache says this:

This command caches credentials in memory for use by future Git programs. The stored credentials never touch the disk, and are forgotten after a configurable timeout.

Since the credentials are stored in memory only, it makes sense that you would lose them whenever you restart. Given that, I can think of a few workarounds for this:

  1. Use git-credential-store instead, which will save your credentials to disk permanently. Note that this will leave them completely unencrypted, so this may not work depending on your security needs.
  2. Continue using cache, but instead of shutting off / restarting your laptop, try using suspend or hibernate mode instead. This will keep the current state of your machine and prevent clearing out the memory each time you use your laptop, so the credentials should persist until the timeout is reached.

Upvotes: 6

Related Questions