Back to Resources

How to Manage Git Credentials in macOS Keychain

Fix GitHub HTTPS authentication on macOS. Check which credential helper Git uses, update the intended account, and verify private repo access.

How to Manage Git Credentials in macOS Keychain

What should you check before changing a credential?

Start in the affected Git checkout. Confirm that its fetch remote uses HTTPS and that your setup uses the macOS Keychain helper, osxkeychain. Update only the entry for the affected host and account. Then verify access with a read-only Git command against a private repository you expect that account to read.

A credential helper supplies authentication details to Git when a remote asks for them. Git can try more than one helper. A Keychain entry can exist while another helper supplies the credential that actually reaches the server. Inspect the helper settings used by the affected checkout before editing a global setting or choosing an entry to update. A custom helper setting may contain a command, so keep those settings local during troubleshooting. Git credential helper reference

Check the fetch remote first. An HTTPS remote typically starts with https://, while an SSH remote may use git@host: or ssh://. For SSH, follow your SSH setup. If the HTTPS remote is handled by Git Credential Manager or GitHub CLI, follow that tool's sign-in workflow. GitHub documents the Keychain procedure for users who manually configured a personal access token with osxkeychain. GitHub's macOS Keychain guide

Git usually passes the HTTPS scheme and host to the helper without the repository path. That means changing a saved entry can affect other checkouts using the same host and account. Git supports path matching through credential.useHttpPath when your setup calls for separate credentials by repository. Check your current setup before changing that choice. Git credential contexts

How do you update the intended GitHub account?

  1. Identify the affected account. In the affected checkout, confirm which remote you expect to use, which account should have access, and how Git is configured to authenticate. For a company repository, confirm the expected organization and its access rules. Stop if you cannot identify the account with confidence.
  2. Find the matching Keychain entry. Open Keychain Access and search for the remote's exact host. Check the account on the matching Internet password entry. If the same host has entries for work and personal accounts, use the one that corresponds to the affected checkout.
  3. Update that entry and authenticate again. If you confirmed the cached value is stale, update the matching entry or remove that single entry and authenticate through your usual Git prompt. Preserve the other entries and credential helper settings. When Git prompts for an HTTPS password under this setup, use the personal access token required by GitHub. GitHub's Keychain instructions

Once you've authenticated again, run a separate read-only check. This gives you a result about repository access even if Keychain Access shows several records that look similar. It also gives you a concrete error to investigate when updating the entry did not resolve the issue.

Architecture Flow
flowchart LR
    A["Confirm HTTPS remote and helper"] --> B["Identify the affected account"]
    B --> C["Update the matching Keychain entry"]
    C --> D["Check access to the private repository"]
    D --> E{"Git returns HEAD?"}
    E -->|Yes| F["Repository read confirmed"]
    E -->|No| G["Check remote, access and repository state"]

How do you verify repository access?

Use an existing checkout with a trusted origin for a private repository you are authorized to read. Pick a repository with an established default branch so the lookup has a HEAD to find. A public repository is useful for testing connectivity. For this check, choose a private one that requires authentication.

Terminalbash
GIT_TERMINAL_PROMPT=0 GIT_ASKPASS=/usr/bin/false \  git ls-remote --exit-code origin HEAD

The lookup lists the remote reference without fetching objects into your checkout or writing to the remote. The command disables Git's terminal and askpass prompts for that invocation. If your credential manager has its own prompt, handle that through your usual sign-in flow before repeating the check. Git ls-remote reference

Expect a commit ID followed by HEAD. The commit ID is a useful observation because it shows the remote returned a ref during the lookup. A successful result confirms that Git's active authentication path could read the repository. It does not identify which helper supplied the credential or establish that the account can push.

A ZeroLabs test on macOS used Apple Git and a loopback server that required a generated fixture credential. The accepted credential returned HEAD. The rejected credential failed the request. A valid credential with a missing ref returned exit status 2. The fixture established how the Git command behaves. It used no live GitHub account or stored macOS credential.

Keep the result short when sharing it for help. Report whether HEAD was returned and whether the error was authentication, connectivity or a missing ref. If the repository is private, omit its name, full remote URL and commit ID unless the person helping you already has access.

What does each result tell you?

ResultWhat to check
A commit ID and HEADConfirm that the remote was the intended private repository. The current authentication path can read it.
Authentication failedRecheck the host, selected helper and account. Confirm the token is still valid and can access the repository.
Repository unavailable or access deniedVerify the repository address, account membership and any organization authorization. Git can reach the host while access to that repository is still denied.
Exit status 2A matching ref was unavailable. Check for an empty repository or an unset default branch before changing credentials.
DNS, connection or TLS errorResolve the network or certificate problem before evaluating a Keychain change.

The distinction matters when the repository was recently created or moved. Updating a credential cannot add a default branch or repair a remote address. Check the error class first and follow the relevant branch of the table. When several helpers are configured, investigate their order before assuming the last credential you edited is the one Git used.

What can a coding assistant check?

A coding assistant can check the configured remote type and helper selection. It can also run the read-only lookup after you authorize the repository. Ask it to report the outcome and a sanitized error category. Keep account selection and Keychain edits in your normal operator workflow. If access depends on an organization sign-in or approval, complete it through the provider's regular interface.

For related Git troubleshooting, see handling cross-platform Git line endings. If Git keeps asking you to sign in, see repeated Git credential prompts.

FAQ

Does a Keychain entry prove GitHub authentication works? Use a read-only check against an authorized private repository. A saved record only describes what is stored for that entry.

Can I run the check on a public repository? A public repository can confirm Git reaches the remote. Use a private repository to verify that your authentication path has read access.

Does a successful lookup prove I can push? It confirms read access to remote refs. Write permissions and branch rules are separate.

Git logo by Jason Long, used under CC BY 3.0.

Share