Skip to content

feat: Add trusted remotes to trust repositories by url - #203

Open
ds-stefanro wants to merge 1 commit into
gabyx:mainfrom
ds-stefanro:feat/trusted-remotes
Open

feat: Add trusted remotes to trust repositories by url#203
ds-stefanro wants to merge 1 commit into
gabyx:mainfrom
ds-stefanro:feat/trusted-remotes

Conversation

@ds-stefanro

Copy link
Copy Markdown

Motivation

In an organization setting, developers clone many repositories from the same trusted source (e.g. their company's GitHub organization). Currently each fresh clone requires answering the trust prompt (per hook, or once per clone with the trust-all marker), which adds friction without a real security decision — the organization's repositories are review-gated and trusted anyway.

What this adds

A new global/local Git configuration githooks.trustedRemotes holding glob patterns which are matched against the url of the remote origin of a repository. Every repository whose remote url matches any pattern is a trusted repository: all its current and future hooks run without showing the trust prompt and without needing the .githooks/trust-all marker.

git hooks config trusted-remotes --add 'https://github.com/my-org/**'

Design details

  • The url is matched as configured in remote.origin.url, no normalization is done, meaning https:// and scp syntax urls need separate patterns. Not matching a pattern only means more prompts, therefore this fails safe.
  • Matching uses / as separator on all platforms (GlobMatchSlashes), therefore * does not match over / but ** does.
  • A repository without a remote origin is never trusted, also not by a pattern like *.
  • An explicit githooks.trustAll setting in a repository takes precedence, meaning a repository whose trust the user denied stays untrusted.

Includes a git hooks config trusted-remotes CLI command (--add, --remove, --print), documentation (README section and CLI docs), and unit tests for the matching and precedence logic.

🤖 Generated with Claude Code

Add the `githooks.trustedRemotes` configuration holding glob patterns
which are matched against the url of the remote `origin` of a repository.
Every repository whose remote url matches any pattern is a trusted
repository, meaning all its current and future hooks run without showing
the trust prompt and without needing the `.githooks/trust-all` marker.

This allows to trust all repositories of an organization one trusts
anyway, e.g. `--add 'https://github.com/my-org/**'`, instead of accepting
the trust prompt once per clone.

Details:

- The url is matched as configured in `remote.origin.url`, no
  normalization is done, meaning `https://` and scp syntax urls need
  separate patterns. Not matching a pattern only means more prompts,
  therefore this fails safe.
- Matching uses `/` as separator on all platforms (`GlobMatchSlashes`),
  therefore `*` does not match over `/` but `**` does.
- A repository without a remote `origin` is never trusted, also not by a
  pattern like `*`.
- An explicit `githooks.trustAll` setting in a repository takes
  precedence, meaning a repository whose trust the user denied stays
  untrusted.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant