Git - How to avoid typing your password repeatedly

There are at least three ways to avoid typing your password repeatedly when using git. First solution requires to use KDE wallet, second solution doesn't require additional tools and third is not the safest one.

First way - use KDE wallet

To store passwords in the KDE wallet you need to install ksshaskpass package:

$ sudo apt-get install ksshaskpass

Then configure git to use it:

$ git config --global core.askpass /usr/bin/ksshaskpass

Alternatively you can use GIT_ASKPASS environmental variable:

$ export GIT_ASKPASS=`which ksshaskpass`

Use secure protocol:

$ git clone --verbose https://user@source.sleeplessbeastie.eu/git/personal_repo.git

Second way - temporarily store passwords in memory

You can temporarily store passwords in memory by using credential helper:

$ git config credential.helper 'cache'

By default credentials are stored for 15 minutes, to change number of seconds to cache credentials use timeout parameter (30 minutes in this example):

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

Use secure protocol:

$ git clone https://user@source.sleeplessbeastie.eu/git/personal_repo.git

To clear credentials cache before time out execute command:

$ git credential-cache exit

Checkout manual pages:

$ man git-credential-cache
$ man gitcredentials

Third way - use ~/.netrc file

You can also store credentials (per host) using plain text in ~/.netrc file:

machine source.sleeplessbeastie.eu login USERNAME password PASSWORD

Make sure that anyone else cannot read file:

$ chmod 0600 ~/.netrc

Use secure protocol:

$ git clone https://source.sleeplessbeastie.eu/git/personal_repo.git
Milosz Galazka's Picture

About Milosz Galazka

Milosz is a Linux Foundation Certified Engineer working for a successful Polish company as a system administrator and a long time supporter of Free Software Foundation and Debian operating system.

Gdansk, Poland https://sleeplessbeastie.eu