The annoying thing about credential errors is that they never point at the cause. You think the network is down; actually the wrong key was used. You think the password is wrong; actually that line was deleted.
Here are three pitfalls that share one property: the first time you meet them, you will not guess them.
1. credential.helper store deletes the line when authentication fails
The easiest way to push over HTTPS:
git config --global credential.helper store
Type the password once and git writes it in plaintext to ~/.git-credentials. No more prompts.
The catch: when the server rejects authentication (401), this helper does not report “authentication failed, try again”. It removes that line from the file.
I hit it in a very ordinary way: a small “change the password” script — update, verify with git ls-remote, roll back on failure. The verification returned 401, git decided the stored credential was invalid and deleted it, and then my script “rolled back” by writing out a file that no longer contained the entry.
Password not changed, credential gone. Rolling back a line that no longer exists is not a rollback.
Never test credentials against the real file. Give the test a throwaway store:
tmp=$(mktemp)
git -c credential.helper="store --file=$tmp" \
-c credential.helper= \
ls-remote https://example.com/repo.git
rm -f "$tmp"
Now a failed attempt burns a temp file, not your only copy.
While we are here: chmod 600 keeps out other users on the box, not you running cat and pasting the output into a chat window. If you can use a key instead, use a key.
2. The same term means opposite things on two platforms
“Deploy key” sounds like a portable concept. It is not:
| Platform | Can a deploy key push? |
|---|---|
| Gitee | No. Read-only, whatever you tick. Returns DeployKey does not support push code |
| GitHub | Yes, if you enable write access when creating it |
So the advice “a deploy key with write access is enough to push” is true on GitHub and quietly false on Gitee. On Gitee, pushing requires an account-level key under profile settings.
You do not need to open the settings page to find out which one is in play — ask the server:
ssh -T git@gitee.com
Hi user(@user)!— account-level key, can pushHi Anonymous (DeployKey)!— deploy key, read-only
That single line is more trustworthy than any documentation, because it reflects the server’s judgement right now. I make it the first step of every credential check.
3. One key cannot serve two repositories
Both hosts enforce it. So either one key per repository, or a single account-level key with broader reach.
With multiple keys, a new problem appears: SSH tries every key in turn, until the server starts rate-limiting you. The symptom is a push that works sometimes, fails other times, or hangs for ten seconds.
Fix it with one alias per repository, and forbid the key hunt:
Host repo-a
HostName ssh.github.com
Port 443
User git
IdentityFile ~/.ssh/id_a
IdentitiesOnly yes
Host repo-b
HostName ssh.github.com
Port 443
User git
IdentityFile ~/.ssh/id_b
IdentitiesOnly yes
Point the remote at the alias (ssh://repo-a/owner/repo.git). IdentitiesOnly yes is the part people skip: without it, IdentityFile is only a preference, not a restriction.
A note on ssh.github.com with port 443. This is not merely “SSH over 443” — it is a separate endpoint GitHub runs, distinct from github.com:22.
The reason I know: github.com once resolved to a bogus IP and ls-remote timed out after 20 seconds, while api.github.com and the SSH endpoint were perfectly healthy. Different services under the same domain can have completely different availability. Do not test one endpoint and declare the network down.
4. The debugging order I use now
Identity first.
ssh -T <alias>— which repository, which kind of key, is it the one you meant?Then write access. Push a throwaway branch and delete it:
git push origin HEAD:refs/heads/permcheck && git push origin :refs/heads/permcheckRead works and write is refused means the key type is wrong — usually a read-only deploy key.
Only then the network.
ls-remotewith atimeout, then try the other endpoint (443 vs 22) and compare.
Order matters. Start with the network and you end up oscillating between “link problem” and “permission problem”, changing things that were never broken.
5. The common thread
All three are the same fact wearing different clothes: credential systems fail silently.
- A 401 does not say “I deleted your password”. It just deletes it.
- A deploy key does not say “I cannot push”. It says
does not support push code. - Multiple keys do not say “I am trying them one by one”. They are just slow.
So rather than memorising conclusions, memorise the moves: test in a throwaway store, identify by handshake, prove write access with a throwaway branch. That covers most of the “the config looks right but it will not push” hours.