git-ecosystem / git-ecosystem/git-credential-manager
First `git push` fails with GCM if multiple credentials exist; second push succeeds
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 9.3k
- Forks
- 2.9k
- Avg merge
- 7d 1h
- Merged PRs (30d)
- 14
Description
Summary
When using Git on Windows 10 with Git Credential Manager (GCM) and pushing to a GitLab remote over HTTPS, my first git push consistently fails with an authentication error. However, the second git push (immediately after) always succeeds.
Environment
- OS: Windows 10
- Git Client: Git Bash (also reproducible from Visual Studio)
- git version 2.39.1.windows.1
- Git Credential Manager version: 2.0.886+ea93cb5158
- Credential Helper:
manager - Remote: GitLab over HTTPS
What happens
Step-by-step:
-
First
git pushfails:remote: HTTP Basic: Access denied [...] fatal: Authentication failed for 'https://gitlab.com/...' -
Second
git pushsucceeds immediately without any prompts or changes.
Investigation
I have both of these credentials stored:
- A
gitlab-ci-token(most likely added by my local GitLab Runner) - My personal GitLab PAT with username
nemecgitlab
Running credential checks confirms this:
printf "protocol=https\nhost=gitlab.com\n\n" | git credential-manager get
→ returns gitlab-ci-token
printf "protocol=https\nhost=gitlab.com\nusername=nemecgitlab\n\n" | git credential-manager get
→ returns my correct PAT
I then added this config explicitly:
git config credential.username nemecgitlab
After that, the first push always works.
Key Insight
Based on Git trace logs and behavior, it appears GCM tries both credentials in sequence:
- First:
gitlab-ci-token→ fails (unauthorized) - Then:
nemecgitlab→ succeeds
However, Git still returns the error from the first attempt, and the push is aborted.
On the next push, GCM reuses the previously successful credential, so it goes through without error.
It seems GCM identifies the correct token in the first attempt, but this is not reflected in Git’s handling of the result.
Expected behavior
If GCM successfully authenticates with a fallback credential, it should not abort the Git operation based on the earlier failure.
Question
Is this behavior expected? Or could it be improved so that the first successful credential attempt (even if preceded by a failure) is honored for that same push?
Thanks!
(For context: GitLab support suggested reporting this here → https://gitlab.com/gitlab-org/gitlab/-/issues/534583)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the first and second push with Git Credential Manager using the two stored GitLab credentials, then compare Git trace logs with git credential-manager get and the credential.username configuration. Investigate how the failed gitlab-ci-token attempt and later successful PAT attempt are reported to Git; done means the first push succeeds when the fallback credential authenticates.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, git
- Domain
- authentication, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100