-2

I tried to enter these commands:

% git config --global user.name "xxx"
% git config --global user.password "xxx"

Then when trying to do a push I still find it asks for the username and password each time

% git push
Username for 'https://github.com': xxx
Password for 'https://xxx@github.com': xxx
Alan2
  • 23,493
  • 79
  • 256
  • 450
  • 2
    user.password isn't a git config setting (so that's just putting a string of text into git config that nothing is reading) user.name only sets the name used when you make a commit - neither of these things relate to GitHub auth, probably wise to start here: https://help.github.com/en/github/using-git/why-is-git-always-asking-for-my-password – AD7six Mar 03 '20 at 08:25
  • I saw there "You can avoid being prompted for your password by configuring Git to store it for you. Once you've configured it, Git automatically uses your cached password when you pull or push a repository." Wondering how to do that. – Alan2 Mar 03 '20 at 08:29
  • 1
    ["Caching your GitHub password in Git"](https://help.github.com/en/github/using-git/caching-your-github-password-in-git) - by clicking on the link the page goes on to mention (:. Note that using `git@` and configuring ssh keys is (I think) the more common way to auth with git and doesn't require any configuration beyond generating a key pair and adding it to your account. – AD7six Mar 03 '20 at 08:32

1 Answers1

2

This and that are different things. user.password is not a git config item at all, and user.name is just the name that'll be used by default when you use git commit: https://git-scm.com/docs/git-config#Documentation/git-config.txt-username

When doing a git push, the prompt you're seeing is for github credentials, a completely unrelated set of identifier which is specific to github and doesn't have to correlate to the user.name (and user.email) you've configured in git.

Git does have a separate category for credentials. You can configure a credential helper which provides git with credentials to use (possibly filtered by domain). By default, git comes with two helpers, cache (which stores the credentials in memory for some time, 15mn by default) and store (which stores the credentials on disk unencrypted).

The former is not very useful if you're only pushing once in a while (though you can increase the timeout to something much larger e.g. a timeout of 30000 would be 8h so you'd have to input your credentials at the start of the day then wouldn't have to worry about it until the next day) and the latter is not very safe (though you could store the store file on an encrypted thumbdrive or something).

There are also credential helpers provided by third parties which can integrated with your system's credential management system if it has one e.g. GCM to integrate with the Windows Credential Store, osxkeychain to integrate with OSX's built-in keychain (that's actually provided with git though somewhat undocumented), etc...

An other alternative is to push/pull over ssh and use ssh-agent to remember your keys and credentials.

Masklinn
  • 34,759
  • 3
  • 38
  • 57