Git asks for username every time I push Git asks for username every time I push linux linux

Git asks for username every time I push


Edit (by @dk14 as suggested by moderators and comments)

WARNING: If you use credential.helper store from the answer, your password is going to be stored completely unencrypted ("as is") at ~/.git-credentials. Please consult the comments section below or the answers from the "Linked" section, especially if your employer has zero tolerance for security issues.

Even though accepted, it doesn't answer the actual OP's question about omitting a username only (not password). For the readers with that exact problem @grawity's answer might come in handy.


Original answer (by @Alexander Zhu):

You can store your credentials using the following command

$ git config credential.helper store$ git push http://example.com/repo.gitUsername: <type your username>Password: <type your password>

Also I suggest you to read
$ git help credentials


You can accomplish this in the .git/config file of your local repository. This file contains a section called 'remote' with an entry called 'url'. The 'url' entry should contains the https link of repository you're talking about.

When you prefix the host 'url' with your username, git shouldn't be asking for your username anymore. Here's an example:

url = https://username@repository-url.com


Permanently authenticating with Git repositories

Run following command to enable credential caching:

$ git config credential.helper store$ git push https://github.com/repo.gitUsername for 'https://github.com': <USERNAME>Password for 'https://USERNAME@github.com': <PASSWORD>

Use should also specify caching expire

git config --global credential.helper "cache --timeout 7200"

After enabling credential caching, it will be cached for 7200 seconds (2 hour).


Read credentials Docs

$ git help credentials