Skip to content

How credential routing works

Every credential you register carries one or more patterns. When Git needs credentials for a remote, the helper decides which configured credential answers.

  1. Git starts a new gh-app-auth helper process for the request. There is no daemon.
  2. The helper reads the host, protocol and path Git provides. With no path it returns empty output; Git sends the repository path only because gitconfig --sync writes useHttpPath for path-specific patterns.
  3. It selects a GitHub App. First it tries the Git --pattern shortcut, then the URL matcher.
  4. If no configured App is selected and the auto mode variables are set, it configures an Auto setup App before any PAT is considered.
  5. It collects any PATs whose patterns match.
  6. It compares the selected App with the matching PATs by priority.
  7. It returns a username and password to Git. For an App, the password is an installation token.

A pattern is a prefix of host/owner/repository, such as github.com/example-org/. A trailing /* is accepted and ignored. Matching works on whole path segments, so github.com/example-org matches github.com/example-org/api but not github.com/example-org-labs/api.

Among all App patterns that match, the longest prefix wins:

App-only URL matching, illustrated

  1. github.com/acme/docsmatches patterngithub.com/acmeselectsOrg App
  2. github.com/tools/buildmatches patterngithub.com/toolsselectsTools App
Simplified App-only URL matching: the longest matching pattern selects the GitHub App. This is not the full App and personal access token resolution, and not how patterns are passed to --patterns.

With both github.com/acme and github.com/acme/api registered, the longer pattern wins for the acme/api repository, and acme/docs still falls back to the broader one. The diagram covers only this App-to-App URL matching. It does not show the --pattern shortcut or how personal access tokens compete with Apps.

If a recorded installation scope says a repository is outside an App’s installation, that App is skipped.

gitconfig --sync configures Git to run the helper with --pattern <pattern> for each pattern, so Git’s own credential-context matching selects the helper. Inside the helper, when that pattern is a prefix of the requested URL (or the reverse), the helper looks for an App with a pattern that matches it and uses the first one found. The Apps are first ordered by how many patterns they list, longest list first. This shortcut is a different mechanism from the URL matcher, and it does not apply the longest-prefix rule. If it finds nothing, the helper falls back to the URL matcher.

The practical consequence: do not assume every App selection is “the globally longest matching prefix”. Keep patterns unambiguous so both mechanisms pick the same App.

A PAT matches when the requested URL starts with the PAT’s pattern after removing https://. This is a plain string prefix. It does not respect path segments, so github.com/acme also matches github.com/acme-labs/tool. End PAT patterns with /.

After an App is selected, it is compared with the matching PATs by priority. This is a separate step from the longest-prefix selection. Do not read it as one global rule of “longest prefix, then priority”.

  • setup --priority defaults to 5 for both Apps and PATs. A hand-written YAML or JSON entry that omits priority loads as 0, for both Apps and PATs. An App at 0 can therefore lose to a PAT registered with setup at 5. Set priority explicitly on both if you want a tie, because the App wins a tie.
  • The Auto setup App is created with priority 5, so it can beat a matching PAT at 5.
  • This comparison happens only in the Git credential helper, not in every command.
  • The App is considered first and a PAT must have a strictly higher priority to win. When priorities tie, the App stays selected in the current implementation.
  • The URL matcher ignores priority when choosing among Apps. It matters only in the App-versus-PAT comparison. It is not deprecated for that purpose.
  • Among several matching PATs, the first with a strictly higher priority wins. Treat equal priorities as undefined and avoid them.

Two credentials whose patterns cover the same repositories at the same specificity make the result depend on details you should not have to remember. Give each credential its own organization or repository prefix, and use a longer pattern for exceptions.

Patterns choose which credential is sent. They do not limit what the token can do. A token’s permissions and repositories come from the GitHub App installation, so restrict access there.