Hiding Github Token in .Gitconfig

How to remove github login popup asking for credentials?

Git has the concept of multiple credential managers. When you installed Git for Windows, it came with the Git Credential Manager for Windows (either the old one or Core), and you probably answered a question about whether you wanted to use it or not.

Somewhere in an earlier config file, such as the system one, there's a setting that looks like credential.helper = manager. Because Git invokes the credential managers in order and uses the first one that provides it credentials, it first asks the manager one specified at the system level, causing the pop-up, and then invokes the store one in your local config file.

What likely happened is that your old account was using the manager helper but the new one is using the store helper for saving your password, so the prompt didn't show up for manager because it had your credentials saved.

If you don't want to the manager helper, run git config -l --show-origin to find the file which has the other credential.helper setting and then edit it to remove that option.

Do note that the manager helper is going to be more secure than storing your credentials in a file on disk (since it will be encrypted), and it will use a personal access token, which GitHub will require in the future, so you may want to use the popup prompt to get credentials and remove the store helper instead.

Update command-line Git credential.helper for Personal Access Tokens (PAT) on GitHub

You should set your credential helper back to what it was: git config --global credential.helper store. Then, use the technique outlined in the Git FAQ to reset the credentials in your credential helper:

$ echo url=https://account@github.com | git credential reject

You should replace account with your GitHub username.

Then, next time, Git will prompt you for your credentials, and you should enter your GitHub username as the username and your personal access token as the password. The credential helper will then save them.

How can I save username and password in Git?

Attention: This method saves the credentials in plaintext on your PC's disk. Everyone on your computer can access it, e.g. malicious NPM modules.

Run

git config --global credential.helper store

then

git pull

provide a username and password and those details will then be remembered later. The credentials are stored in a file on the disk, with the disk permissions of "just user readable/writable" but still in plaintext.

If you want to change the password later

git pull

Will fail, because the password is incorrect, git then removes the offending user+password from the ~/.git-credentials file, so now re-run

git pull

to provide a new password so it works as earlier.

Is it possible to include a file in your .gitconfig

Git (1.7.10+) now supports this syntax in .gitconfig:

[include]
path = /path/to/file

See here for a detailed description of the git change and its edge cases.

By the way, a couple of subtleties worth pointing out:

  1. Environment-variable expansion, e.g. $HOME, is not supported. (Expansion of ~ appeared in Git 1.7.10.2.)

  2. If a relative path is specified, then it is relative to the .gitconfig file that has the [include] statement. This works correctly even across chained includes -- e.g. ~/.gitconfig can have:

    [include]
    path = subdir/gitconfig

    and subdir/gitconfig can have:

    [include]
    path = nested_subdir/gitconfig

    ... which will cause subdir/nested_subdir/gitconfig to be loaded.

  3. If git can't find the target file, it silently ignores the error. This appears to be by design.



Related Topics



Leave a reply



Submit