Git: How to avoid typing username & password when using HTTPS Authentication

Isaac Jumba
2 min readSep 7, 2015

--

Probably most of us experience the scenario below when using Git in Ubuntu.

So how do we go about bypassing this tedious and at times, annoying step? Two approaches can be used. The first approach involves taking a different route altogether. This is to mean using a different authentication technique. SSH keys are a way to identify trusted computers, without involving passwords. One needs to generate an SSH key and add the public key to your GitHub account. A guide on how to set up SSH key can be found here

But this is not the main focus for this article. The key question remains:

Is there a way to skip typing my username and/password when using HTTPS in GitHub?

The answer is yes. This is done by using credential helpers. And this is the second approach. Credential helpers basically tells Git to remember your GitHub username and password every time it talks to GitHub. The syntax is given by:

git config credential.https://example.com.username myusername
git config credential.helper “$helper $options”

Therefore, credential helpers are external programs from which Git can request both usernames and passwords. Credential helpers are in two forms: cache which caches credentials in memory for a short period of time, and store which basically stores credentials indefinitely on disk.

Once you have selected the helper, you can tell Git to use it by putting its name into the credential.helper variable.

  1. Find a helper:
git help -a | grep credential-credential-foo

2. Read its description.

 git help credential-foo

3. Tell Git to use it.

git config — global credential.helper foo

Assuming you have a remote with the following URL https://github.com/adambajumba/MestEIT, update the Git configuration to use the helper whenever it needs authentication steps:

$ git config --global \credential.https://github.com/myusername/mysecretproject.username \your_github_account_name$ git config --global \credential.https://github.com/adambajumba/MestEIT.adambajumba \IsaacJumba

Note that the remote URL is appended with a trailing .username fragment which becomes the key and the GitHub username becomes the value.Once the username is set, map the helper: And you are done! That easy, right?

$ git config --global core.askpass ~/.git_credential_helper.rb

An example of how it works would be:

$ git config credential.helper store
$ git push http://example.com/repo.git
Username: <type your username>
Password: <type your password>
[several days later]
$ git push http://example.com/repo.git
[your credentials are used automatically]

In conclusion, the credential helper does not work in all versions of git but from version 1.8 and above.

--

--