3

I always clone private Github repos via HTTPS. I have personal access token to use as "password" when git asked for it for the first time.

For a very long time, I was able to do git operations without git asking for credentials for every single command when I run things in command line.

But these days it always ask for credentials in command line!

I have tried various combinations for changing git config credentials.helper (changing to store/wincred/manager/cache) and a bunch of other things, nothing works.

Funny thing is, if I run git command inside VSCode terminal, then it will not ask for credentials and just work. But I do not want to have to fire up VSCode every time I need to do some git stuffs (especially when my computer is running low on RAM due to other tasks)

I need a permanent way to fix this issue while still using HTTPS remote url + personal access token

I am using Git for Windows git version 2.40.0.windows.1

My current horrible .gitconfig after trying many online guides

[credential "github.com"]
    authority = Github
    interactive = never
    preserve = true
[credential]
    helper = manager
    modalPrompt = true
    writelog = true
John London
  • 1,250
  • 2
  • 14
  • 32

3 Answers3

3

I finally found the root cause

Apparently it is because git-credential-manager.exe is not found in PATH

Once I do set PATH=C:\Git\mingw64\bin;%PATH% and do one git push, I am prompted with web browser Github login, and then things just work now

John London
  • 1,250
  • 2
  • 14
  • 32
2

On Windows use manager-core and specify the provider. For github we want the github provider, Bitbucket has a bitbucket provider and there is a generic one for normal use.

So to setup for generic as the default and use the github provider for github specifically use:

git config --global credential.helper manager-core
git config --global credential.provider generic
git config --global credential.github.com.provider github

If you are using an Atlassian Bitbucket local server - use generic. The 'bitbucket' provider is for their cloud service.

patthoyts
  • 32,320
  • 3
  • 62
  • 93
1

With Git 2.39+, the GCM (Git Credential Manager from Microsoft) is no longer "manager-core", as I explained here.

I use only git config --global credential.helper manager for any remote server (GitHub, GitLab, Bitbucket local server)

Just make sure to see your GitHub token (PAT) when doing:

printf "host=github.com\nprotocol=https" | git credential-manager get

That printf command works even in a simple Windows CMD (no bash needed), provided your %PATH% includes:

set "GH=%ProgramFiles%\Git"
set "PATH=%GH%\bin;%GH%\cmd;%GH%\usr\bin;%GH%\mingw64\bin;%GH%\mingw64\libexec\git-core;%PATH%"

Not only that allows using printf (%GH%\usr\bin), but also git-credential-manager(-core).exe (%GH%\mingw64\bin).

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Although your solution wasn't what solved my issue exactly, it did lead me to it, so I will give you the bounty! – John London Apr 17 '23 at 13:37
  • @JohnLondon "Apparently it is because `git-credential-manager.exe` is not found in `PATH`": that is indeed part of what I meant, when I said "provided your `%PATH%` includes:" it applies more than just `printf`, and the `PATH` I proposed did include `%GH%\mingw64\bin`. I have edited the answer to make that more visible. – VonC Apr 17 '23 at 19:06