Repository navigation
Description
Problem Description
devops repos worktrees add <issue> -r <clone of a private repo> fails at git ls-remote --heads origin with no HTTPS credential. Before the failure, it already removed worktrees of the clone. On 2026-11-18 an agent ran it for the clone of dan-petty/homelab (a private repository). The command removed 4 merged worktrees, then stopped with fatal: could not read Username for 'https://github.com': No such device or address. The agent also found the clone in detached HEAD after the run. The same clone fetches with no problem from the shell of the person.
Reproduced on 2026-11-18 with run_subprocess(["git", "-C", <clone>, "ls-remote", "--heads", "origin", "main"], check=False, quiet=True): exit 128 with the error above for the homelab clone, exit 0 for the devops-cli clone. devops-cli is public, so its origin needs no credential.
Cause
build_subprocess_env(src/devops_cli/core/process.py) does not pass theGIT_*keys. The devcontainer sets the github.com credential helpergh auth git-credentialwithGIT_CONFIG_*keys, so a git child of devops has no such helper. The process runner givesGH_TOKENto a git child that reaches a remote, but git reads that token only through the helper.- fix(infra): read the default branch at origin, not the working tree #5162 added
CONST_GIT_GITHUB_CREDENTIAL_CONFIG(git -c credential.https://github.com.helper=...) for the git calls ofdevops infra.src/devops_cli/infra/repo_tree.py:58andsrc/devops_cli/k8s/argocd_overrides.pyuse it._gitinsrc/devops_cli/git/worktree_add.py:178does not, sols-remoteandfetchofworktrees addhave no credential. Thefetch --pruneofsrc/devops_cli/git/operations.pydoes not use it either. worktrees_addinsrc/devops_cli/commands/repos.py:654runsreclaim_merged_worktreesbeforeadd_worktreereadsorigin. A failed read oforiginthus comes after the removals.- The detached HEAD: no code path is found yet.
git/worktree_add.pyand the reclaim have no--detachof the main clone.
Expected vs Actual Behavior
Expected: each git call of devops that reaches GitHub gets the credential of the session, as the git calls of devops infra do. A run that cannot pass its preconditions changes nothing in the clone.
Actual: the git calls of worktrees add have no credential for a private repository, and the reclaim removes worktrees before the read of origin fails.
Proposed Fix
- Fix the cause in one place: the process runner adds the credential
-cvalues where it givesGH_TOKENto a git child that reaches a remote (git_reaches_remote). Then each git network call gets the helper and the token together, and no caller must remember the-cvalues. - Read
origin(onegit ls-remote --heads origin) before the reclaim, so that a failed read removes no worktree.
Acceptance Criteria
- A test: a git child that reaches a remote gets the credential helper of the session. It fails on
main(devops ci fail-to-pass). - A test: when the read of
originfails,worktrees addremoves no worktree and does not change the HEAD of the clone. - A live run of
devops repos worktrees addon a clone of a private repository creates the worktree.
Related
#5529 (the first fetch of a private repository in a new Service pod fails), #5162.
Alternatives check of 2026-11-19: in-use.
The repository already uses this tool.
Tool: cli/cli (https://github.com/cli/cli), MIT, last activity 2026-11-18, maintained.
Reason: Searches found the GitHub CLI credential helper gh auth git-credential, which the project already uses. It supplies GitHub HTTPS credentials from GH_TOKEN to git network calls, but it cannot reorder worktrees add before the reclaim or guard HEAD.
Covers:
- Supplies GitHub HTTPS credentials from GH_TOKEN
- Works as a git credential helper for ls-remote and fetch
- Already configured in the project's devcontainer and used by devops infra
Lacks:
- Cannot read origin before the reclaim
- Cannot stop worktree removal when the origin read fails
- Does not explain or fix the detached HEAD
Proposed design
Problem statement
devops repos worktrees add fails with fatal: could not read Username for 'https://github.com' on a clone of a private repository. The git child that runs git ls-remote --heads origin gets no GitHub credential helper. The command also removes merged worktrees before that read, so the failure changes the clone. The change gives the existing helper to each git child that reaches a remote and reads origin before the reclaim. The detached HEAD that the run left has no known code path and is deferred.
Acceptance criteria
Requirement: Credential for ls-remote
The process runner SHALL give the credential helper of CONST_GIT_GITHUB_CREDENTIAL_CONFIG to a git child that runs ls-remote against a remote.
Scenario: The reproduction form with a token
- WHEN A test runs
git -C <clone> ls-remote --heads origin mainthrough the process runner withGH_TOKENset to a token and a git executable that records its arguments. - THEN The recorded command holds the
-cvalues ofCONST_GIT_GITHUB_CREDENTIAL_CONFIGbeforels-remote, and the child environment holdsGH_TOKEN.
Requirement: Credential for fetch
The process runner SHALL give the credential helper of CONST_GIT_GITHUB_CREDENTIAL_CONFIG to a git child that runs fetch against a remote.
Scenario: A fetch with prune
- WHEN A test runs
git fetch --prune originthrough the process runner withGH_TOKENset to a token and a git executable that records its arguments. - THEN The recorded command holds the
-cvalues ofCONST_GIT_GITHUB_CREDENTIAL_CONFIGbeforefetch, and the child environment holdsGH_TOKEN.
Requirement: No credential for a local git child
The process runner MUST NOT give the credential helper or a GitHub token to a git child that reaches no remote.
Scenario: A local status
- WHEN A test runs
git statusthrough the process runner withGH_TOKENset to a token and a git executable that records its arguments. - THEN The recorded command holds no
-ccredential value, and the child environment holds noGH_TOKEN.
Requirement: Failed origin read changes nothing
worktrees add SHALL read origin before it removes any worktree, and MUST change nothing when that read fails.
Scenario: ls-remote exits 128
- WHEN A test runs
worktrees addon a clone whosegit ls-remote --heads originexits 128. - THEN The command exits non-zero, the clone keeps every worktree, and the HEAD of the clone is the same as before the run.
Requirement: Successful origin read reclaims and adds
worktrees add SHALL remove the merged worktrees and create the worktree when the origin read succeeds.
Scenario: One merged worktree
- WHEN A test runs
worktrees addon a clone whosegit ls-remote --heads originexits 0 and that holds one merged worktree. - THEN The command removes that worktree, creates the worktree of the issue, and exits 0.
Existing Tool Considered
The alternatives check in the issue body records in-use for cli/cli (https://github.com/cli/cli), MIT, maintained. The repository already uses the GitHub CLI credential helper gh auth git-credential. devops infra passes it through CONST_GIT_GITHUB_CREDENTIAL_CONFIG. The block records what the tool covers and lacks. The change gives its -c values to each git child that reaches a remote, and it reads origin before the reclaim. It does not fix the detached HEAD on a successful run, which is deferred.
Key questions
- Which open, maintained tool covers the GitHub credential that a git child needs?: The alternatives check in the issue body records
in-useforcli/cli(gh auth git-credential), because the repository already uses it. The change reusesCONST_GIT_GITHUB_CREDENTIAL_CONFIGin the process runner. The block records what the tool covers and lacks. [sources: src/devops_cli/config/constants.py:1211, src/devops_cli/infra/repo_tree.py, src/devops_cli/core/process.py] - Where does the process runner add the credential helper?: The process runner adds the values in the code that gives
GH_TOKENto a git child thatgit_reaches_remoteaccepts. The child gets the-cvalues ofCONST_GIT_GITHUB_CREDENTIAL_CONFIGbefore its subcommand. (best practice) [sources: src/devops_cli/core/process.py, src/devops_cli/config/constants.py:1211, src/devops_cli/git/worktree_add.py, src/devops_cli/git/operations.py]- Chosen: Process runner for each git child that reaches a remote. One place covers
ls-remoteandfetch --prune, and no caller must remember the values. - Rejected: Each caller passes the constant. The defect is two callers that forgot it, and a third caller can forget it again.
- Chosen: Process runner for each git child that reaches a remote. One place covers
- How does the runner give the
-cvalues to the child?: The runner inserts-c <key>=<value>after thegitword and before the subcommand. It uses the values ofCONST_GIT_GITHUB_CREDENTIAL_CONFIG. (best practice) [sources: src/devops_cli/core/process.py, src/devops_cli/config/constants.py:1211]- Chosen: Command-line
-cvalues after thegitword. It reusesCONST_GIT_GITHUB_CREDENTIAL_CONFIGand does not depend on the filteredGIT_CONFIG_*keys. - Rejected:
GIT_CONFIG_COUNTandGIT_CONFIG_KEY_0in the child environment.build_subprocess_envfilters the environment andCONST_GIT_ISOLATED_CONFIG_ENVisolates git config.
- Chosen: Command-line
- Does the change cover the
fetch --pruneofsrc/devops_cli/git/operations.py?: Yes. The process runner gives the helper and the token to a git child that runs a network subcommand, andfetchis such a subcommand. The caller insrc/devops_cli/git/operations.pyneeds no change. [sources: src/devops_cli/git/operations.py, src/devops_cli/core/process.py] - Which order does
worktrees_addrun in?:worktrees_addreadsoriginonce, beforereclaim_merged_worktrees, and uses that result for the add. A failed read then removes no worktree, and the add does not read again. (best practice) [sources: src/devops_cli/commands/repos.py, src/devops_cli/git/worktree_add.py]- Chosen: Read
originonce before the reclaim. A failed read changes nothing, and a second read cannot fail after the removals. - Rejected: Keep the order and make the reclaim undoable. A removed worktree cannot be restored, so the command needs more code and a record of each removal.
- Chosen: Read
- Is the detached HEAD of the clone in scope?: No. The body records no code path that detaches HEAD. This change stops before any change when the origin read fails, and the test asserts that HEAD is unchanged on that path. A detachment on a successful run needs its own evidence and its own issue, which is deferred. (best practice) [sources: src/devops_cli/git/worktree_add.py, src/devops_cli/commands/repos.py]
- Chosen: Defer the detached HEAD on a successful run. The body records no code path that detaches HEAD, so this change can state no test and no fix.
- Rejected: Investigate the detachment in this change. The cause is unknown, so the change cannot state a test or a fix.
- Does a git child that reaches no remote keep its current behavior?: Yes.
_github_pingives a token only whengit_reaches_remoteis true. Another git child gets an empty pin, no token lookup and no credential helper. [sources: src/devops_cli/core/process.py]
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Nov 18, 2026
A CLI command fails for private repos and removes worktrees before the failure, causing data loss.Both modify the process runner for git children that reach a remote, but #5265 restricts token access while the candidate adds the credential helper to those calls.devops-cli-service commentedon Nov 19, 2026
Waiting for the alternatives check to run. The next refine round looks at the item again after the check records a verdict.
devops-cli-service commentedon Nov 19, 2026
The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.
Searches (8)
Tools considered:
Searches run:
Sources:
devops-cli-service commentedon Nov 19, 2026
Status set to Ready at 5e6822d (see proposed design in issue body).
Moved to new items: #6354.
41 remaining items
fix(repos): Regenerate the command page of repos (#6340)
docs(openspec): archive the change (#6340)
fix(repos): Make check tests pass (#6340)
fix(repos): Make check strength pass (#6340)
fix(repos): Drop the credential values that callers pass twice (#6340)
Revert "fix(repos): Drop the credential values that callers pass twice (
fix(repos): Give the credential values once to a caller that passes t…
devops-cli-service commentedon Nov 21, 2026
Released in v0.188.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.188.0
devops-cli-service commentedon Nov 21, 2026
Live since 2026-11-21 14:28 UTC
refactor(git): git uses the configured credential helper (#6663)