You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Exit status 5 from git when running gh repo set-default #7770
I have a local clone of repository which I forked to submit a PR. However, when running gh pr create, I mistakenly selected my fork in the answer to Where should we push the 'foobar' branch? (due to the switcharoo that gh does when forking a repo).
When I noticed the error, I closed the PR in my fork and attempted to set the upstream repo as the default for PRs, by doing gh repo set-default. This resulted in the following output:
$ gh repo set-default This command sets the default remote repository to use when querying theGitHub API for the locally cloned repository.gh uses the default repository for things like: - viewing and creating pull requests - viewing and creating issues - viewing and creating releases - working with Actions - adding repository and environment secrets? Which repository should be the default? gnunn1/tilixfailed to run git: exit status 5
Note the error at the bottom: "failed to run git: exit status 5".
However, running gh pr create afterwards does show that the default remote was indeed set, so I'm not sure what the error message is about.
@waldyrious It could be an issue with git's permissions on your system. If you're using VSCode, you can use the debugger to run the repo set-default command and get a clearer understanding of where the error occurred. Here's an example of a VSCode launch.json config to get it working:
{
// Use IntelliSense to learn about possible attributes.// Hover to view descriptions of existing attributes.// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387"version": "0.2.0",
"configurations": [
{
"name": "Run 'gh repo set-default'",
"type": "go",
"request": "launch",
"mode": "auto",
"args": [
"repo",
"set-default"
],
"cwd": "<the path to a repo you want to run set-default on>",
"program": "${workspaceFolder}/cmd/gh",
"console": "integratedTerminal"
}
]
}
I'm guessing the error is happening somewhere around here:
@waldyrious From the git docs: "you try to unset an option which does not exist (ret=5)". When doing repo set-default we try to unset the previously set default repo and it is likely this git command that is failing. It is a bit of a mystery as to why though. We do a check to make sure there was a previously set default before running the unset operation. Are you able to reproduce this error? If so, it would be helpful if you could paste the git config file for the repo, redacted as necessary. Also, running the command with GH_DEBUG=1 environment variable set will help verify my above hypothesis about the unset command being the culprit.
Re-reading the opening comment, I believe the reproduction steps may indeed be related to selecting the wrong remote to push a branch when creating a PR. Here's what I wrote back then:
when running gh pr create, I [...] selected my fork in the answer to Where should we push the 'foobar' branch? [...]
When I noticed the error, I closed the PR in my fork and attempted to set the upstream repo as the default for PRs, by doing gh repo set-default. This resulted in the [error described in this issue].
This was exactly what happened this time again, with a different repo: the PR I tried to create with gh pr create was created in my fork instead of in the upstream repo (I did select my repo as the answer to the "Where should we push the 'foobar' branch?" question), so I attempted to use set-default and ran into the same exit code 5 issue.
Ah, I meant without running any other commands. Running repo set-default might have altered your git config. At this point, without any further commands, can you copy and paste your .git/config again please? Hard to see how the get would work but the delete wouldn't.
Could you run git config --list --show-origin | grep gh-resolved from inside the git repository as well? This would hopefully tell us which file the config might be coming from.
@ardnew am I right in understanding that this repo is a dotfiles repo for you?
There's something funny going on here that the file you have linked looks like a global git config but it has a remote block for gh-resolved. Is your dotfiles repo public somewhere, if this is the case?
Do you also have a file /home/andrew/.config/.git/config and a /home/andrew/.gitconfig?
There's something funny going on here that the file you have linked looks like a global git config but it has a remote block for gh-resolved. […]
Do you also have a file /home/andrew/.config/.git/config [sic] and a /home/andrew/.gitconfig
Nope, just the former.
/home/andrew/.config/git/config is indeed my global gitconfig, and the fork in which I encountered the error is cloned to /opt/gogll/src.
I too have never understood why gh relentlessly adds this to my global gitconfig, regardless of repo or path. I'll remove it, and the next gh command I run will reinsert it. It has done this for years, but I never believed it was causing an issue.
Maybe [user.useConfigOnly] could be causing an issue? I don't have access to that PC at this very moment. Will verify and respond when I do.
I too have never understood why gh relentlessly adds this to my global gitconfig, regardless of repo or path. I'll remove it, and the next gh command I run will reinsert it. It has done this for years, but I never believed it was causing an issue.
😅 Well, this gh-resolved config key is supposed to be per repo to indicate which remote is the base (default). For example, when you clone a fork the upstream is set to the default e.g. in my fork of huh:
So something funny is going on if it is ending up in your global config for sure! That may or may not be related to the exit status 5 you are seeing, but definitely suspicious.
Coming back to this after a long while, I think I have now finally managed to get to the bottom of this. Indeed, as @williammartin probably suspected, and like @ardnew, the culprit in my case was a gh-resolved = base entry under [remote "origin"] in my global~/.gitconfig, rather than anything in the repo-level .git/config I pasted above.
Just to be clear, to avoid conflating two situations: in my case the global gh-resolved was not something gh kept reinserting; I had added it to my global ~/.gitconfig manually, years ago, to make gh always treat origin as the base repo (so I wouldn't have to manually run set-default in every fork after PR #6738 disabled the interactive default repo picker in gh pr create, replacing it with an error message 😢). When I switched to a new computer, I didn't set the config in my current ~/.gitconfig, and it was not automatically reinserted by gh; so I stopped bumping into the "exit 5" error (hence forgetting —again!— about this issue), and now instead have to run set-default whenever I fork a new repo. 🤷
So, from what I could gather, here's what is causing the issue: gh repo set-default decides whether a default is already set via remotes.ResolvedRemote(), which is populated by reading git config --get-regexp '^remote\..*\.gh-resolved$'; the problem is that, with no scope flag, git config reads the merged configuration across system/global/local, so gh sees the entry coming from the global ~/.gitconfig and concludes there's a current default to clear. It then calls UnsetRemoteResolution, which runs git config --unset remote.origin.gh-resolved, and that command, with no --global/--local flag, defaults to writing the repo-local config. Since the entry isn't in the local config (it's global), git finds nothing local to unset and returns exit 5 ("trying to unset an option which does not exist"), which gh surfaces as failed to run git: exit status 5.
So the underlying issue is an asymmetry between gh's read and write paths for the gh-resolved config: the resolution is read across all config scopes, but the unset action only targets the local scope.
Here are the self-contained reproduction steps, using an isolated HOME/config to avoid interference with the real git config (no gh or network needed, since the bug is purely about the git config commands that gh invokes):
# Point $HOME at a throwaway temp dir, and the global git config at a file within it (for the current shell session only)
$ export HOME=$(mktemp -d)
$ export GIT_CONFIG_GLOBAL="$HOME/.gitconfig"
# The root cause: a gh-resolved entry in the *global* config
$ git config --global remote.origin.gh-resolved base
# Demo: a repo with an 'origin' remote but no *local* gh-resolved
$ git init -q "$HOME/repo"&&cd"$HOME/repo"
$ git remote add origin https://github.com/octocat/Hello-World.git
# Confirm that gh's detection reads the merged local+global config, and thus sees the global entry:
$ git config --get-regexp '^remote\..*\.gh-resolved$'remote.origin.gh-resolved base
# Confirm that the local scope config is empty:
$ git config --local --get-regexp '^remote\..*\.gh-resolved$';echo"exit: $?"exit: 1
# The kicker: The unset that gh runs (local-scoped by default) fails with exit 5:
$ git config --unset remote.origin.gh-resolved;echo"exit: $?"exit: 5
When the gh-resolved entry is instead present locally (which happens after one runs gh repo set-default), the same unset succeeds (exit 0). My global gh-resolved config entry was a manual workaround to gh's default forking flow, rather than something gh does (or offers to do, even), which explains why most people never hit this.
IMHO the right fix for this bug would be for gh's paths for detection and unsetting of gh-resolved to agree on git config scope.
One approach would be to have both read only local config, so that a global gh-resolved doesn't get detected as a clearable local default in the first place. That matches what @williammartin said above:
this gh-resolved config key is supposed to be per repo
That said, the reason I and @ardnew felt the need to specify it as a global key was precisely to set this once as a default and avoid having to configure each repo individually, and forcing the reading of gh-resolved to ignore the global config would break our use case (and the usual expectations for how git's configuration scopes are supposed to cascade). So IMHO the correct solution would be to skip the clearing of gh-resolved if it is not defined in the local repo, thus avoiding the exit 5 issue.
I'll prepare a PR to fix this, which, after all this time and effort from everyone involved, seems like the least I could do! 😅
@waldyrious thanks for the detailed investigation! Always handy to have the additional information.
Regarding preparing PRs, we're absolutely slammed at the moment with agents going brrrr, so unfortunately we have little time to get round to reviewing external PRs. You can create it and it might be useful for us to see in future, but honestly it may not go anywhere and I don't want you to waste your time.
Ah, no problem, and thanks for the heads-up! I'll refrain from submitting a PR but will try to provide timely feedback (famous last words, amirite? 🫣) once one is opened. 😃
Activity
harveysanders commentedon Jul 31, 2023
@waldyrious What OS are you using?
harveysanders commentedon Jul 31, 2023
@waldyrious It could be an issue with
git's permissions on your system. If you're using VSCode, you can use the debugger to run therepo set-defaultcommand and get a clearer understanding of where the error occurred. Here's an example of a VSCodelaunch.jsonconfig to get it working:{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Run 'gh repo set-default'", "type": "go", "request": "launch", "mode": "auto", "args": [ "repo", "set-default" ], "cwd": "<the path to a repo you want to run set-default on>", "program": "${workspaceFolder}/cmd/gh", "console": "integratedTerminal" } ] }I'm guessing the error is happening somewhere around here:
cli/pkg/cmd/repo/setdefault/setdefault.go
Lines 225 to 239 in f777bec
You can pop a breakpoint in and step through to see if you can get more information on what's happening.
I hope that is somewhat helpful
samcoe commentedon Jul 31, 2023
@waldyrious From the
gitdocs: "you try to unset an option which does not exist (ret=5)". When doingrepo set-defaultwe try to unset the previously set default repo and it is likely thisgitcommand that is failing. It is a bit of a mystery as to why though. We do a check to make sure there was a previously set default before running the unset operation. Are you able to reproduce this error? If so, it would be helpful if you could paste thegitconfig file for the repo, redacted as necessary. Also, running the command withGH_DEBUG=1environment variable set will help verify my above hypothesis about the unset command being the culprit.[-]Git error when running `gh repo set-default`[/-][+]Exit status 5 from git when running `gh repo set-default`[/+]williammartin commentedon Jan 16, 2024
Closing this due to inactivity but feel free to reopen if it's still an issue and we can move it forward.
waldyrious commentedon Mar 6, 2025
OMG, I'm so sorry! I somehow totally missed the notifications for this issue.
I can still reproduce the error (with
ghversion 2.67.0). Here's the output with the debug flag set (in another repository):For reference, here's the output of the git commands listed above:
Let me know if there are any additional input you'd need to debug the issue!
@williammartin I don't have the permissions to reopen, but please do so if you can. I promise I'll be more responsive this time! 😅
williammartin commentedon Mar 7, 2025
That's very strange! If possible can you share the entire
.git/configfile?harveysanders commentedon Mar 7, 2025
For more context, exit code
5can also happen if there are multiple matches:https://www.kernel.org/pub/software/scm/git/docs/git-config.html
It looks like there's only one though, per your regexp...hmm
1 remaining item
waldyrious commentedon Mar 10, 2025
Re-reading the opening comment, I believe the reproduction steps may indeed be related to selecting the wrong remote to push a branch when creating a PR. Here's what I wrote back then:
This was exactly what happened this time again, with a different repo: the PR I tried to create with
gh pr createwas created in my fork instead of in the upstream repo (I did select my repo as the answer to the "Where should we push the 'foobar' branch?" question), so I attempted to useset-defaultand ran into the same exit code 5 issue.williammartin commentedon Mar 11, 2025
From your provided git config, I cannot see how this would possibly happen:
Can you try running it again just to double check? Very strange!
waldyrious commentedon Mar 11, 2025
Sure:
williammartin commentedon Mar 11, 2025
Ah, I meant without running any other commands. Running
repo set-defaultmight have altered your git config. At this point, without any further commands, can you copy and paste your.git/configagain please? Hard to see how thegetwould work but thedeletewouldn't.Could you run
git config --list --show-origin | grep gh-resolvedfrom inside the git repository as well? This would hopefully tell us which file the config might be coming from.ardnew commentedon Jan 1, 2026
I'm also encountering this same issue.
$ git config --list --show-origin | grep gh-resolved file:/home/andrew/.config/git/config remote.origin.gh-resolved=baseApologies for the long
.gitconfig. Didn't want to snip something I didn't realize was important to the issue:williammartin commentedon Jan 6, 2026
@ardnew am I right in understanding that this repo is a dotfiles repo for you?
There's something funny going on here that the file you have linked looks like a global git config but it has a
remoteblock forgh-resolved. Is your dotfiles repo public somewhere, if this is the case?Do you also have a file
/home/andrew/.config/.git/configand a/home/andrew/.gitconfig?ardnew commentedon Jan 7, 2026
@williammartin no, not a dotfiles repo.
Nope, just the former.
/home/andrew/.config/git/configis indeed my global gitconfig, and the fork in which I encountered the error is cloned to/opt/gogll/src.I too have never understood why
ghrelentlessly adds this to my global gitconfig, regardless of repo or path. I'll remove it, and the nextghcommand I run will reinsert it. It has done this for years, but I never believed it was causing an issue.Maybe
[user.useConfigOnly]could be causing an issue? I don't have access to that PC at this very moment. Will verify and respond when I do.ChasmOfDeath commentedon Jan 7, 2026
williammartin commentedon Jan 7, 2026
😅 Well, this
gh-resolvedconfig key is supposed to be per repo to indicate which remote is thebase(default). For example, when you clone a fork the upstream is set to the default e.g. in my fork ofhuh:So something funny is going on if it is ending up in your global config for sure! That may or may not be related to the exit status 5 you are seeing, but definitely suspicious.
waldyrious commentedon Sep 3, 2026
Coming back to this after a long while, I think I have now finally managed to get to the bottom of this. Indeed, as @williammartin probably suspected, and like @ardnew, the culprit in my case was a
gh-resolved = baseentry under[remote "origin"]in my global~/.gitconfig, rather than anything in the repo-level.git/configI pasted above.Just to be clear, to avoid conflating two situations: in my case the global
gh-resolvedwas not somethingghkept reinserting; I had added it to my global~/.gitconfigmanually, years ago, to makeghalways treatoriginas the base repo (so I wouldn't have to manually runset-defaultin every fork after PR #6738 disabled the interactive default repo picker ingh pr create, replacing it with an error message 😢). When I switched to a new computer, I didn't set the config in my current~/.gitconfig, and it was not automatically reinserted by gh; so I stopped bumping into the "exit 5" error (hence forgetting —again!— about this issue), and now instead have to runset-defaultwhenever I fork a new repo. 🤷So, from what I could gather, here's what is causing the issue:
gh repo set-defaultdecides whether a default is already set viaremotes.ResolvedRemote(), which is populated by readinggit config --get-regexp '^remote\..*\.gh-resolved$'; the problem is that, with no scope flag,git configreads the merged configuration across system/global/local, so gh sees the entry coming from the global~/.gitconfigand concludes there's a current default to clear. It then callsUnsetRemoteResolution, which runsgit config --unset remote.origin.gh-resolved, and that command, with no--global/--localflag, defaults to writing the repo-local config. Since the entry isn't in the local config (it's global), git finds nothing local to unset and returns exit 5 ("trying to unset an option which does not exist"), whichghsurfaces asfailed to run git: exit status 5.So the underlying issue is an asymmetry between
gh's read and write paths for thegh-resolvedconfig: the resolution is read across all config scopes, but the unset action only targets the local scope.Here are the self-contained reproduction steps, using an isolated
HOME/config to avoid interference with the real git config (noghor network needed, since the bug is purely about the git config commands that gh invokes):When the
gh-resolvedentry is instead present locally (which happens after one runsgh repo set-default), the same unset succeeds (exit 0). My globalgh-resolvedconfig entry was a manual workaround to gh's default forking flow, rather than somethingghdoes (or offers to do, even), which explains why most people never hit this.IMHO the right fix for this bug would be for gh's paths for detection and unsetting of
gh-resolvedto agree ongit configscope.One approach would be to have both read only local config, so that a global
gh-resolveddoesn't get detected as a clearable local default in the first place. That matches what @williammartin said above:That said, the reason I and @ardnew felt the need to specify it as a global key was precisely to set this once as a default and avoid having to configure each repo individually, and forcing the reading of gh-resolved to ignore the global config would break our use case (and the usual expectations for how git's configuration scopes are supposed to cascade). So IMHO the correct solution would be to skip the clearing of gh-resolved if it is not defined in the local repo, thus avoiding the exit 5 issue.
I'll prepare a PR to fix this, which, after all this time and effort from everyone involved, seems like the least I could do! 😅
williammartin commentedon Sep 3, 2026
@waldyrious thanks for the detailed investigation! Always handy to have the additional information.
Regarding preparing PRs, we're absolutely slammed at the moment with agents going brrrr, so unfortunately we have little time to get round to reviewing external PRs. You can create it and it might be useful for us to see in future, but honestly it may not go anywhere and I don't want you to waste your time.
waldyrious commentedon Sep 3, 2026
Ah, no problem, and thanks for the heads-up! I'll refrain from submitting a PR but will try to provide timely feedback (famous last words, amirite? 🫣) once one is opened. 😃