Languages
[Edit]
EN

Git - save password under Linux

9 points
Created by:
sienko
323

In this article, we want to show how to save username and password for gitĀ under Linux when we don't want to type it each time during push / pull operations.

Quick solution (run following command):

git config credential.helper store

or:

git config --global credential.helper store

Where: --global causes saving the password in a common place (only forĀ logged-in user).

Ā 

Read the below section to know details about quick solutions and alternatives.

1. git credential store example

This approach uses git credential store that stores passwords in simple plain text fileĀ - it is not safe when the file system is not encrypted.

Simple steps:

  1. run terminal,
  2. run following command:
    git config credential.helper store
  3. run following commandĀ in the project directory:
    git pull
    or any other git command that requires authentication,
  4. we will be asked to provide aĀ username and password to our git account - do it andĀ confirm the action,
  5. future git authentications for this git account will useĀ .git-credentials file.

Note: path to passwords location isĀ ~/.git-credentials.

2. Cached passwords

It is possible to cache passwords only for some time. That approach keeps passwords only indicated amount of the time - so we need to type password only when idle time is bigger than indicated in configuration.

Use the following command:

git config credential.helper cache

or with a time of password storing (in seconds):

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

WhereĀ --timeout=3600 means keeping the password 1 hour.

References

  1. Git config - docs

Git

Native Advertising
šŸš€
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

ā¤ļøšŸ’» šŸ™‚

Join