Take the 2-minute tour ×


share|improve this question
See also superuser.com/questions/199507/… –  Colonel Panic Mar 27 '13 at 16:27
You now can use a credential helper to encrypt the _netrc file containing your credentials. See my answer below. I found that safer that the git-credential-winstore.exe (memory cache) which is a bit buggy on Windows. –  VonC Aug 21 '13 at 15:50
add comment

13 Answers

up vote 643 down vote accepted

With git version 1.7.9 and later


With git 1.7.9 or later, you can just use one of the following credential helpers:

git config --global credential.helper cache



(That example was suggested in the GitHub help page for Linux.) You can also store your credentials permanently if so desired, see the other answers below.


git config --global credential.helper osxkeychain

For Windows, there is a helper called git-credential-winstore.exe.

For Linux, you can use gnome-keyring.

With git versions before 1.7.9




git config remote.origin.url https://you:password@github.com/you/example.git


With any git version (well, since v0.99)


machine <hostname> login <username> password <password>


chmod 600 ~/.netrc


share|improve this answer
Don't store your password in plain text. As of Git 1.7.9 you can use credential helpers. git config --global credential.helper osxkeychain on OS X. For other OS see help.github.com/articles/set-up-git –  dazonic Jun 22 '12 at 7:29
FWIW credential.cache settings don't work in windows see stackoverflow.com/questions/11693074/… –  rogerdpack Sep 24 '13 at 20:08
is the osxkeychain only for https repos urls? or does it work also when using ssh repos urls + keys? –  chovy Oct 29 '13 at 22:52
show 6 more comments


url = git://github.com/you/projectName.git
pushurl = git@github.com:you/projectName.git


share|improve this answer
add comment


git config credential.helper store



git config --unset credential.helper
share|improve this answer
On Windows, you can download a helper utility configures things to store an encrypted version of your GIT password in the Windows Creditial Store, see confluence.atlassian.com/display/STASH/… –  Contango Jan 22 '13 at 18:39
I found that I had to specify --global or it would try to store the settings in the current repository: git config --global credential.helper store –  Brian Gordon May 15 '13 at 3:25
Why would do the cache instead of storing permanently? Sharing computers or something? –  Michael Calkins Aug 24 '13 at 15:42
Hm "store permanently using the following" after what? I'm getting an error that it can't lock ".git/config". Who creates that file? –  Victor Eijkhout May 16 at 23:23
@VictorEijkhout - use the command from within the repository directory or use the global option as Brian Gordon suggested a couple of comments above. –  StarNix May 19 at 4:59
show 1 more comment




Download the binary git-credential-osxkeychain.

Run the command below to ensure the binary is executable:

chmod a+x git-credential-osxkeychain

Put it in the directory /usr/local/bin.

Run the command below:

git config --global credential.helper osxkeychain
share|improve this answer
add comment


$ cat ~/.netrc
machine github.com login lot105 password howsyafather


share|improve this answer
Make sure to also chmod 0600 ~/.netrc. –  poolie May 31 '13 at 3:58
add comment

You can use credential helpers.

git config --global credential.helper 'cache --timeout=x'

where x is the number of milliseconds.

share|improve this answer
add comment

TLDR; Use an encrypted netrc file with git 1.8.3+.

Saving a password for git repo https url is possible with a ~/.netrc (Unix) or %HOME%/_netrc (note the _) on Windows.

But: that file would store your password in plain text.

Solution: encrypt that file with gpg (the GNU Privacy Guard), and make git decrypt it each time it needs a password (for push/pull/fetch/clone operation)

Step-by-Step instructions for Windows

With Windows:

(git has a gpg.exe in its distribution, but using a full gpg installation includes a gpg-agent.exe, which will memorize your passphrase associated to your gpg key)

  • install gpg4Win Lite, the minimum gnupg command-line interface (take the most recent gpg4win-vanilla-2.X.Y-betaZZ.exe), and complete your PATH with the gpg installation directory

    set PATH=%PATH%:C:\path\to\gpg
    copy C:\path\to\gpg\gpg2.exe C:\path\to\gpg\gpg.exe

(Note the 'copy' command: git will need a bash to execute the command 'gpg'. Since gpg4win-vanilla-2 comes with gpg2.exe, you need to duplicate it)

  • create or import a gpg key, and trust it

    gpgp --import aKey
    # or
    gpg --gen-key

(Make sure to put a passphrase to that key)

  • trust that key

  • Install the credential helper script in a directory within your %PATH%

    cd c:\a\fodler\in\your\path
    curl -o c:\prgs\bin\git-credential-netrc https://raw.github.com/git/git/master/contrib/credential/netrc/git-credential-netrc

(yes, this is a bash script, but it will work on Windows since it will be called by git)

  • Make a _netrc file in clear text

    machine a_server.corp.com
    login a_login
    password a_password
    protocol https
    machine a_server2.corp.com
    login a_login2
    password a_password2
    protocol https

(don't forget the 'protocol' part: 'http' or 'https' depending on the url you will use)

  • encrypt that file

    gpg -e -r a_recipient _netrc

(you now can delete the _netrc file, keeping only the _netrc.gpg encrypted one)

  • use that encrypted file

    git config --local credential.helper "netrc -f C:/path/to/_netrc.gpg -v"

(Note the '/': C:\path\to... wouldn't work at all)
(You can use at first -v -d to see what is going on)

From now on, any git command using an http(s) url which requires authentication will decrypt that _netrc.gpg file and use the login/password associated to the server you are contacting.
The first time, gpg will ask you for the passphrase of your gpg key, to decrypt the file.
The other times, the gpg-agent launched automatically by the first gpg call will provide that passphrase for you.

That way, you can memorize several url/login/passwords in one file, and have it stored on your disk encrypted.
I find it more convenient than a "cache" helper", where you need to remember and type (once per session) a different password for each of your remote services, for said password to be cached in memory.

share|improve this answer
trying the same thing on linux .. git config --local credential.helper "netrc -f /home/me/.netrc.gpg -v -d" ..and i get "git : 'credential-netrc' is not a git command. see 'git --help'" –  sunny Dec 21 '13 at 3:26
@sunny That is what the curl -o c:\prgs\bin\git-credential-netrc https://raw.github.com/git/git/master/contrib/credential/netrc/git-credential-ne‌​trc is for: you need to copy the git-credential-netrc anywhere in your path ($PATH), in order for git to be able to call 'credential-netrc'. –  VonC Dec 22 '13 at 0:14
Thanks had missed that. –  sunny Dec 23 '13 at 17:49
add comment

There's an easy, old-fashioned way to store user credentials in a HTTPS URL:


You can change the URL with git remote set-url <remote-repo> <URL>

The obvious downside to that approach is that you have to store the password in plain text. You can still just enter the user name (https://user@github.com/...) which will at least save you half the hassle.

You might prefer to switch to SSH or to use the GitHub client software.

share|improve this answer
add comment

I got my answer from https://www.kernel.org/pub/software/scm/git/docs/v1.7.9/gitcredentials.html. For my case, I dont have credential-cache in my windwos, I use credential-store. After I use credential-store, the username/password are stored in [user folder]/.git-credentials file. To remove the username/password, just delete the content of the file.

share|improve this answer
add comment

For windows you can use this plugin:


The nice thing about it is that it saves the password in Windows Credential Store not as plan text (See the link for more details)

share|improve this answer
add comment

An authentication token should be used instead of the account password. Go to gibhub settings/applications then create a personal access token. The token can be used the same way a password is used.

The token is intended to allow users not use the account password for project work. Only use the password when doing admin work, like creating new tokens or revoke old tokens.

share|improve this answer
add comment

The composer documentation mentions that you can prevent it from using the github API, so that it acts like git clone:

If you set the no-api key to true on a github repository it will clone the repository as it would with any other git repository instead of using the GitHub API. But unlike using the git driver directly, composer will still attempt to use github's zip files.

So the section would look like this:

"repositories": [
        "type": "vcs",
        "no-api": true,
        "url": "https://github.com/your/repo"

Keep in mind that the API is there for a reason. So it this should be a method of last resort regarding the increased load on github.com.

share|improve this answer
add comment

Simply add a new remote as

git remote -rm origin 

git remote add origin https://username:mypassword@github.com/path/to/repo.git

that's it now you don't need to enter password again and again

share|improve this answer
add comment

Your Answer


