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.
What happens on a request
Section titled “What happens on a request”- Git starts a new
gh-app-authhelper process for the request. There is no daemon. - 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 --syncwritesuseHttpPathfor path-specific patterns. - It selects a GitHub App. First it tries the Git
--patternshortcut, then the URL matcher. - If no configured App is selected and the auto mode
variables are set, it configures an
Auto setupApp before any PAT is considered. - It collects any PATs whose patterns match.
- It compares the selected App with the matching PATs by priority.
- It returns a username and password to Git. For an App, the password is an installation token.
The URL matcher
Section titled “The URL matcher”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
github.com/acme/docsmatches patterngithub.com/acmeselectsOrg Appgithub.com/acme/apimatches patterngithub.com/acme/apiselectsAPI Appgithub.com/tools/buildmatches patterngithub.com/toolsselectsTools App
--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.
The Git --pattern shortcut
Section titled “The Git --pattern shortcut”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.
Personal access tokens
Section titled “Personal access tokens”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 /.
Comparing Apps and PATs
Section titled “Comparing Apps and PATs”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 --prioritydefaults to5for both Apps and PATs. A hand-written YAML or JSON entry that omitspriorityloads as0, for both Apps and PATs. An App at0can therefore lose to a PAT registered withsetupat5. Setpriorityexplicitly on both if you want a tie, because the App wins a tie.- The
Auto setupApp is created with priority5, so it can beat a matching PAT at5. - 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
prioritywhen 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.
Avoid ambiguous overlaps
Section titled “Avoid ambiguous overlaps”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 are not an access policy
Section titled “Patterns are not an access policy”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.