2

So, here's what we're trying to do:

$ git config --global credential.helper store
$ git config --global user.name myname
$ git config --global user.password mypassword
$ tmpdir=`mktemp -d`
$ cd $tmpdir
$ git init
$ git remote add origin <https github URL ending in .git>
$ git pull

When $ git pull runs, I'm prompted for username & password again. My understanding is that once I've set the username & password globally, shouldn't git automatically pick up on that? I need to be running these steps as a part of an automation feature and providing username & password explicitly in the https git url (or via tha prompt) wouldn't help.

How do I set it up so I don't have to manually provide the credentials at all times?

Saturnian
  • 1,686
  • 6
  • 39
  • 65
  • 1
    Possible duplicate of [Git asks for username every time I push](https://stackoverflow.com/questions/11403407/git-asks-for-username-every-time-i-push) – Charlie Sep 05 '19 at 18:10

2 Answers2

2

I think this happens because you're using the https remote url.

According to this explanation from GitHub:

Using an HTTPS remote URL has some advantages: it's easier to set up than SSH, and usually works through strict firewalls and proxies. However, it also prompts you to enter your GitHub credentials every time you pull or push a repository.

You can use a credential helper to tell Git to remember your GitHub username and password every time it talks to GitHub.

Turn on the credential helper so that Git will save your password in memory for some time. By default, Git will cache your password for 15 minutes.

Set git to use the credential memory cache

$ git config --global credential.helper cache

Set the cache to timeout after 1 hour (setting is in seconds)

$ git config --global credential.helper 'cache --timeout=3600'
matkv
  • 652
  • 1
  • 7
  • 18
0

I don't believe user.password is a valid configuration.
And user.name is only for commit authorship, not for authentication.

If you want to cache your credentials in advance, you would do so with git ls-remote (for a private repository)

git ls-remote https://url/private/epository.git
# prompt for username/password
# enter username and password

Then any init/remote add/pull command will not prompt for username/password, reusing those cached for that URL domain.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250