Skip to content

gh issue develop --base outside a git repository creates the branch, then exits 1 without printing its URL #14856

Open

Description

@AXEG0

Describe the bug

gh issue develop <n> -R OWNER/REPO --name <branch> --base <base>, run from a directory that is not inside a git repository, creates the linked branch on GitHub, then exits 1 with failed to run git: fatal: not in a git directory and prints no URL. A branch that was created reads as a failed command, and a script that checks the exit code treats it as a failure. Repeating the command with the same --name outside a repository fails the same way, because the existing-branch path reaches the same step.

The cause is the order in developRunCreate: after CreateLinkedBranch succeeds (develop.go#L261), the --base value is written as branch.<name>.gh-merge-base with git config (#L278-L283), and an error there returns before the URL is printed (#L285). The local steps after the URL already allow running outside a repository: checkoutBranch returns nil when no remotes are found, unless --checkout was given (#L353-L364). The branch-config write is the one local step that assumes a repository. This code is the same on trunk (674516f) and in v2.103.3.

Related, not duplicates: the write came with the gh-merge-base support in #9712 (for #10089). #12575 and #12651 fixed a different failure of the same line (an empty branch name written into .git/config). #9072 asks in general for no repository requirement where an operation does not touch one; here the remote work succeeds and only the local base-branch hint fails.

Affected version

gh version 2.96.0 (2026-07-02)
https://github.com/cli/cli/releases/tag/v2.96.0

Also reproduced with the latest release:

gh version 2.103.3 (2026-10-26)
https://github.com/cli/cli/releases/tag/v2.103.3

git version 2.50.1, Linux aarch64.

Steps to reproduce the behavior

Use a repository OWNER/REPO where you can create branches, an issue <n> in it with no linked branches, and an empty directory that is not inside a git repository. Times are UTC, 2026-10-28.

  1. In the empty directory, gh 2.96.0, 14:47:24: gh issue develop <n> -R OWNER/REPO --name <branch-a> --base main. Exit 1, stdout empty, stderr failed to run git: fatal: not in a git directory. Afterwards gh api repos/OWNER/REPO/branches/<branch-a> returns the branch and gh issue develop --list <n> -R OWNER/REPO lists it.
  2. Control, same directory without --base, 14:47:26: gh issue develop <n> -R OWNER/REPO --name <branch-b>. Exit 0, prints github.com/OWNER/REPO/tree/<branch-b>.
  3. Control, step 1's command in a fresh git init directory with no remotes, 14:47:28: gh issue develop <n> -R OWNER/REPO --name <branch-c> --base main. Exit 0, prints github.com/OWNER/REPO/tree/<branch-c>, and git config --get branch.<branch-c>.gh-merge-base there returns main.
  4. Step 1 with gh 2.103.3, 14:47:44: --name <branch-d>. Exit 1, the same error, stdout empty, branch created.
  5. Step 4 repeated with the same --name <branch-d>, 14:47:45. Exit 1, the same error; GH_DEBUG=true shows the failing call is git config branch.<branch-d>.gh-merge-base main.
  6. Step 4 with a new name and GH_DEBUG=true, 14:47:53: --name <branch-e>. Exit 1, branch created; debug log below.

Before this reproduction the same failure showed up twice in normal use (2026-10-27 11:40Z and 2026-10-28 13:13Z), both run outside any repository, and in both GitHub's repository activity records the branch creation at the time of the failing call.

Expected vs actual behavior

Expected: outside a repository, --base creates the branch, prints its URL and exits 0, as the command does without --base. The command's own code sets that behaviour for the other local steps: the test case "develop new branch outside of local git repo" in develop_test.go expects the URL and no error, and checkoutBranch bails out silently when "the command was not run from inside a git directory" (#L356-L358). Inside a repository, branch.<name>.gh-merge-base is still written. With --checkout, an error outside a repository stays, as checkoutBranch already returns one.

Actual: exit 1, failed to run git: fatal: not in a git directory, no URL on stdout, and the linked branch exists on GitHub.

The existing outside-a-repository test case sets no BaseBranch, so this path has no test today; a --base variant of that case would cover it.

Logs

# 2026-10-28T14:47:24Z, empty directory outside any git repository, gh 2.96.0
$ gh issue develop <n> -R OWNER/REPO --name <branch-a> --base main
failed to run git: fatal: not in a git directory
# exit 1, stdout empty

# 2026-10-28T14:47:26Z, same directory, no --base
$ gh issue develop <n> -R OWNER/REPO --name <branch-b>
github.com/OWNER/REPO/tree/<branch-b>
# exit 0

# 2026-10-28T14:47:28Z, fresh git init directory with no remotes
$ gh issue develop <n> -R OWNER/REPO --name <branch-c> --base main
github.com/OWNER/REPO/tree/<branch-c>
# exit 0
$ git config --get branch.<branch-c>.gh-merge-base
main

# 2026-10-28T14:47:35Z
$ gh issue develop --list <n> -R OWNER/REPO
<branch-a>	https://github.com/OWNER/REPO/tree/<branch-a>
<branch-b>	https://github.com/OWNER/REPO/tree/<branch-b>
<branch-c>	https://github.com/OWNER/REPO/tree/<branch-c>
GH_DEBUG=true, gh 2.103.3, step 6 (new branch, empty directory), full stderr, timestamps cut to milliseconds
$ GH_DEBUG=true gh issue develop <n> -R OWNER/REPO --name <branch-e> --base main
* Request at 2026-10-28 14:47:53.683 +0000 UTC
* Request to https://api.github.com/graphql
* Request took 292.680777ms
* Request at 2026-10-28 14:47:53.976 +0000 UTC
* Request to https://api.github.com/graphql
* Request took 373.390274ms
* Request at 2026-10-28 14:47:54.350 +0000 UTC
* Request to https://api.github.com/graphql
* Request took 186.698001ms
* Request at 2026-10-28 14:47:54.537 +0000 UTC
* Request to https://api.github.com/graphql
* Request took 235.275504ms
* Request at 2026-10-28 14:47:54.773 +0000 UTC
* Request to https://api.github.com/graphql
* Request took 717.826486ms
[git config branch.<branch-e>.gh-merge-base main]
failed to run git: fatal: not in a git directory
# exit 1, stdout empty

Activity

  1. cli-triage commented on Oct 28, 2026

    @cli-triage

    Thanks for the detailed report and investigation! I verified the cited source at commit 674516f:

    • In developRunCreate, after the linked branch is created on GitHub, opts.GitClient.SetBranchConfig(...) is called unconditionally whenever --base is set, before the URL is printed and before checkoutBranch runs.
    • SetBranchConfig shells out to git config branch.<name>.gh-merge-base <base> with no guard for "not in a git directory", so it returns an error that aborts the command before the URL line is reached.
    • By contrast, checkoutBranch, which runs later, already tolerates being invoked outside a git repository (it swallows the "no remotes found" error unless --checkout was passed).

    This matches the reported symptom: the remote linked branch is created successfully, but the local git config write fails and the command exits 1 without printing the branch URL, even though the equivalent run without --base succeeds. Suggesting bug and the gh-issue command label; priority-3 since the remote operation itself succeeds and a workaround exists (run from inside a git repo). No duplicate found — related issues (#12986, #13805, #9072, #12575, #12651) address different failure modes of gh issue develop.

    Generated by Issue Triage (skills-driven) for #14856 · copilot · auto · 90.8 AIC · ⊞ 4.5K · ◷

  2. added
    bug
    priority-3
    gh-issue
    on Nov 2, 2026
  3. removed
    needs-triage
    on Nov 2, 2026
  4. AXEG0 commented on Nov 12, 2026

    @AXEG0
    Author

    @cli/code-reviewers I'd like to send the fix for this one. Could it get the help wanted label? Here are Acceptance Criteria I'd propose, taken from the expected behaviour above:

    • Outside a git repository, gh issue develop <n> -R OWNER/REPO --name <branch> --base <base> creates the linked branch, prints its URL and exits 0, as it already does without --base.
    • Inside a repository, branch.<name>.gh-merge-base is still written, as today.
    • With --checkout outside a repository, the command still returns an error, as checkoutBranch does today.
    • A --base variant of the test case "develop new branch outside of local git repo" in develop_test.go covers the first point.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggh-issuepriority-3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions