Repository navigation
Description
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.
- 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, stderrfailed to run git: fatal: not in a git directory. Afterwardsgh api repos/OWNER/REPO/branches/<branch-a>returns the branch andgh issue develop --list <n> -R OWNER/REPOlists it. - Control, same directory without
--base, 14:47:26:gh issue develop <n> -R OWNER/REPO --name <branch-b>. Exit 0, printsgithub.com/OWNER/REPO/tree/<branch-b>. - Control, step 1's command in a fresh
git initdirectory with no remotes, 14:47:28:gh issue develop <n> -R OWNER/REPO --name <branch-c> --base main. Exit 0, printsgithub.com/OWNER/REPO/tree/<branch-c>, andgit config --get branch.<branch-c>.gh-merge-basethere returnsmain. - Step 1 with gh 2.103.3, 14:47:44:
--name <branch-d>. Exit 1, the same error, stdout empty, branch created. - Step 4 repeated with the same
--name <branch-d>, 14:47:45. Exit 1, the same error;GH_DEBUG=trueshows the failing call isgit config branch.<branch-d>.gh-merge-base main. - 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
cli-triage commentedon Oct 28, 2026
Thanks for the detailed report and investigation! I verified the cited source at commit 674516f:
developRunCreate, after the linked branch is created on GitHub,opts.GitClient.SetBranchConfig(...)is called unconditionally whenever--baseis set, before the URL is printed and beforecheckoutBranchruns.SetBranchConfigshells out togit 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.checkoutBranch, which runs later, already tolerates being invoked outside a git repository (it swallows the "no remotes found" error unless--checkoutwas passed).This matches the reported symptom: the remote linked branch is created successfully, but the local
git configwrite fails and the command exits 1 without printing the branch URL, even though the equivalent run without--basesucceeds. Suggestingbugand thegh-issuecommand label;priority-3since 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 ofgh issue develop.fix: `gh issue develop --base` outside a git repository creates t (cl…
AXEG0 commentedon Nov 12, 2026
@cli/code-reviewers I'd like to send the fix for this one. Could it get the
help wantedlabel? Here are Acceptance Criteria I'd propose, taken from the expected behaviour above: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.branch.<name>.gh-merge-baseis still written, as today.--checkoutoutside a repository, the command still returns an error, ascheckoutBranchdoes today.--basevariant of the test case "develop new branch outside of local git repo" indevelop_test.gocovers the first point.