Direct Answer & TL;DR
- Root Cause: The macOS Keychain often holds stale credentials from a previous account, preventing Git from prompting for new login details.
- The Solution: Use
git credential-osxkeychain eraseto manually wipe the incorrect credentials from your Keychain. - Verification: By using
git remote -vto identify the domain andgetto inspect the Keychain, I was able to clearly see where the credentials were mixed up.
It’s a frustrating experience: you can see your repository in the browser, but the moment you try a git clone or git pull in the terminal, it throws a cold ‘Not Found’ error. I’ve encountered this most often after changing my macOS user account or switching to a new Git identity.
fatal: repository 'https://gitlab.test.com/project/code.git/' not found
After some digging, I found that this isn’t necessarily about the repository missing. For security, Git servers often return “Not Found” instead of “Permission Denied” when authentication fails.
The problem was that my Mac was stubbornly clinging to stale or incorrect credentials, never giving me a chance to input my new details. Here’s how I tracked down the source and fixed it.
Investigation: What was stored in my system?
First, I compared my remote repository URL with what the Keychain was actually holding.
Finding the service domain (Host)
To query the Keychain, I first needed the domain of the repository service. I used git remote -v to extract the domain part (e.g., github.com or gitlab.test.com) from my remote address.
- If you have the local source: Check the output of
git remote -v. - If you don’t have the source: Just identify the domain from the repository’s URL in your browser.
git remote -v
Inspecting the actual Keychain data
I inserted the domain I found into the command below to see exactly what credentials my macOS Keychain was holding. To my surprise, it was still showing my old username.
printf "protocol=https\nhost=gitlab.test.com\n" | git credential-osxkeychain get
If you see your previous username like the example below, you’ve found the culprit:
username=previous_username
password=stored_password_or_token
The Solution: Wiping the stale credentials
Since the problem was outdated data, I solved it by manually wiping it clean.
Clearing the Keychain data (Clean Up)
I ran the following command to forcibly remove the authentication info for that specific host from my macOS Keychain:
printf "protocol=https\nhost=gitlab.test.com\n" | git credential-osxkeychain erase
[!IMPORTANT] Since the command provides no output on success, it means my Keychain has been successfully cleared of that entry.
Logging in with my new account (Re-authenticate)
I tried my git pull again, and I finally saw the long-awaited prompt for my Username and Password (or Token).
Once I provided the new details, the command executed successfully, and my Keychain was updated with the fresh credentials.
[!TIP] Note: I used a Token instead of a password Most platforms like GitHub and GitLab now strictly require Personal Access Tokens (PAT) for Git operations. When the prompt appeared, I pasted my Token value into the password field rather than my actual account password.
💡 Summary: Efficient Troubleshooting Workflow
| Step | Action | Command |
|---|---|---|
| 1. Verify | Inspect current Keychain data | ... get |
| 2. Erase | Immediately delete stale data | ... erase |
| 3. Re-login | Enter new account info (PAT, etc.) | git pull / clone |
Check all settings at once
git config --list --show-origin
This command shows which file (System/Global/Local) each setting comes from, making it easy to spot where the config went wrong.
Final Thoughts: I hope this helps others in the same shoes
Most Git authentication issues I’ve faced on macOS weren’t really about config files; they were almost always about ‘stale data’ lingering in the Keychain. It took me a full hour of head-scratching to realize this, but the process of using get and erase helped me understand how macOS actually handles security.
If you’re currently stuck with a Repository not found error, I highly recommend checking your Keychain data first before diving into complex configuration tweaks.
Summary of Steps:
- Inspect stale data using the
getcommand. - Immediately delete incorrect credentials with
erase. - Re-authenticate (
pull/clone) to update the Keychain with new info.
🔗 References
- [Git Official Docs] git-config - Detailed explanation of config scopes
- [Git Official Docs] gitcredentials - Credential system overview