Skip to content
Start » git » Temporary cache of GIT credentials – username and password

Temporary cache of GIT credentials – username and password

There are situations where you need to work with a repository GIT using the HTTPs protocol and cannot permanently store user credentials in local configuration. One solution is to temporarily cache the credentials (username and password) for a limited time.

git-credential-cache is the helper we are going to use to temporarily store the passwords in the memory.

Also see how to set the author of a Git command for a single run of the command in this quick tip, or yet How to configure username and email per project with Git.

The command git-credential-cache

git config credential.helper 'cache [ ]'

Description

This command stores credentials in memory for use for a given time by the Git program.

Stored credentials are never stored on disk and are forgotten after a configurable timeout.

The cache can be accessed through a Unix domain socket, restricted to the current user by file system permissions.

Options

Some options are available when using the command:

--timeout

Specifies the time in seconds to cache credentials. The default value is 900 which is equivalent to 15 minutes.

--socket

use the option socket specifying the path (path on disk) to contact a daemon cache daemon running, or start a new cache daemon if not already started.

The default is $XDG_CACHE_HOME/git/credential/socket, unless ~/.git-credential-cache/ exists, if the path exists ~/.git-credential-cache/socket is used instead.

If your home directory is on a network-mounted file system, you may need to change it to a local file system.

When using this option you must specify an absolute path.

controlling the daemon

If you want the daemon exit before the configured time, thus forgetting all cached credentials before they time out, you can use an exit command:

git credential-cache exit

Examples

The purpose of using this helper is to reduce the number of times you will need to enter username and password in a short space of time, for example, when you are making deployment adjustments on a test server.

Check out the usage example below.

git config credential.helper cache git push https://gitlab.com/palavrasagrada.git Username: Password: [after 5 minutes] git push https://gitlab.com/palavrasagrada.git [Your cached credentials will be used automatically within the time limit]

In this site update example Holy Word Bible, the developer called the helper credential.helper cache before performing the first push.

On the first interaction with the repository, GIT asks for the username and password to be provided, the developer normally executes by typing them.

After 5 minutes of working on the source code, a new push will be executed by the developer, however, this time the cached credentials are used without having to enter username and password again.

This will happen for the helper's standard 15 minute time frame.

To increase the time limit, you can use the option --timeout providing the seconds:

$ git config credential.helper 'cache --timeout=3600'

In the example above the time set will be 1 hour.

keep up to date

Don't forget to follow me on twitter and sign the Mazer.dev channel on Youtube to receive updates on new articles, video lessons and free courses in software development and engineering.

More on GIT, Github and Gitlab

How to resolve “error: src refspec main does not match any” in Git
The error message: "error: src refspec main does not match any" happens for some routinely common causes, particularly when starting a new project repository. A second message line with the text: "error: …
Free e-books on programming and computing in general
Looking for free e-books on programming, software development, and other areas of computing? This list includes these topics as well as books on software engineering and other subjects. The pandemic period has exploded…
Git quick tip: git checkout specific files from another branch
The git checkout command can be used to update specific files or directories in your working tree with those in another branch, without having to merge the entire branch. This can be …
Creating the README of your profile on Github
Customize the README of your profile on Github, make your programmer business card "your face" and increase the visibility and clarity of your technical position in the area of software development. …
semantic git commits
Semantic commits in the use of Git and other VCS (code versioning systems) are the best way to document implementation execution, as they give context to change management. Write commit messages…
How to fix slow GIT with SSH on Github, Gitlab or Bitbucket
To fix slow push and pull GIT commands, when we are using ssh keys in Github, Gitlab and Bitbucket repositories services, it is necessary to change the IP version configuration used. I like …

1 thought on “Cache temporário das credenciais GIT – username e password”

  1. Pingback: Git - quick tips, commands and tutorials - MAZER.DEV

Leave a Reply

Your email address will not be published.

en_USEnglish
%d bloggers like this: