Skip to content

Search repositories with git-rg

Prefer glab for GitLab or gh for GitHub when working with repositories, issues, or PRs/MRs. Use the git-rg Skill and CLI to find functions, settings, or error text in remote code. Searches target a branch, tag, or commit without cloning repository history.

Enable the git-rg Skill for the Agent, then provide the repository, branch, and search target. For example:

Use git-rg to find request timeout settings on the main branch of https://gitlab.example.com/team/service.git. List file paths, line numbers, and relevant code.

In obscli, type $ to select the git-rg Skill before sending your task. Public repositories often allow anonymous reads; private repositories require credentials available in the Agent's runtime environment.

Prefer an existing gh or glab login

Install and sign in to the corresponding CLI under the account and environment that actually runs the Agent:

# GitHub
gh auth login --hostname github.com

# GitLab: replace with your host
glab auth login --hostname gitlab.example.com

Since v0.4.0, git-rg defaults to --auth auto: it checks environment tokens first, then reuses the target host's gh/glab login. There is no separate git-rg login command.

A login in your personal terminal is not automatically available to an Agent running under another account or inside a container. Host installation currently has no standard way to inject repository tokens through environment variables, so this guide provides no host ENV setup steps. Prefer an existing CLI login under the Agent's account. The default Agent image includes git-rg but does not preinstall gh/glab; containers can use ENV as described below.

Configure a token for containers

Use a token that can read the target repository. For GitLab, prefer a read-only identity with read_api. For GitHub, prefer a fine-grained token restricted to the target repository with Contents: read. Do not put tokens in chat messages, repository URLs, or Git commits.

Docker

Add this entry to your existing obs-agent.env file:

GITRG_TOKEN=replace-with-repository-read-token

Restrict access to the file:

chmod 600 obs-agent.env

Follow the container installation guide to recreate the container with its existing three persistent volumes and --env-file ./obs-agent.env. Editing the host's env file or running docker restart does not update an existing container's environment.

Kubernetes / Helm

Add GITRG_TOKEN to the existing obs-agent-secret Secret, preserving AGENT_ID, AGENT_API_KEY, and other existing keys. Also declare the injected keys in Helm values:

secret:
  existingSecret: obs-agent-secret
  keys:
    - AGENT_API_KEY
    - AGENT_ID
    - GITRG_TOKEN

Load these values in your existing Helm installation or upgrade command. Preserve any additional secret.keys already configured. For plain Kubernetes YAML, reference this key using secretKeyRef in the Agent container's env. After updating the Secret, recreate or roll out a restart of the Pods; existing processes do not automatically receive new environment variables.

GITRG_TOKEN works with GitHub, GitLab, and self-managed hosts and takes precedence over CLI logins. It is not scoped by host. When one Agent accesses hosts requiring different identities, prefer separate gh/glab logins for each host.

Minimal command examples

Run these commands in the Agent's environment, replacing example repositories and branches. Put all options before the search text and repository address.

# List branches and tags on self-managed GitLab
git-rg refs --provider gitlab https://gitlab.example.com/team/service.git

# Search a branch for literal text, showing paths, lines, and two context lines
git-rg --provider gitlab --ref main --format text -F -C 2 \
  'request_timeout' https://gitlab.example.com/team/service.git

# Search Go files in a GitHub repository
git-rg --ref main --glob '*.go' --format text -F \
  'request_timeout' github:OWNER/REPO

Add --auth env to explicitly use container environment credentials only. To verify complete coverage, use the default NDJSON output and check the final summary.complete. Reaching a result limit or searching only an index means that no matches cannot prove the repository contains no matching code.

For auth_unavailable or private repository access failures, check the runtime account's CLI login or container token, the target host, and repository read permissions. Self-managed GitLab requires --provider gitlab. An SSH-style repository address does not enable SSH key authentication.

See the git-rg guide for all options.

Feedback

Is this page helpful?