Skip to content

fix(git): checkout DWIMs remote-only branches (#277)#278

Merged
fdaviddpt merged 1 commit into
masterfrom
fix/git-checkout-remote-only-277
Jun 1, 2026
Merged

fix(git): checkout DWIMs remote-only branches (#277)#278
fdaviddpt merged 1 commit into
masterfrom
fix/git-checkout-remote-only-277

Conversation

@fdaviddpt
Copy link
Copy Markdown
Contributor

Closes #277.

git-checkout:REF failed with not found even after fetch for a branch that exists on a remote but was never checked out locally — common when updating a teammate's / bot's MR. git's own DWIM (checkout <branch> → create local tracking branch) can fail to fire (e.g. checkout.guess=false, or a fetch that only moved FETCH_HEAD).

Fix

When the checkout fails as a pathspec error, find the single remote carrying refs/remotes/<remote>/REF and create the local tracking branch explicitly via git checkout -b REF --track <remote>/REF. Multiple remotes match → error like git does. No match → existing not found error.

Tests

TestCheckoutRemoteOnlyBranch (3 cases): resolves a remote-only branch, resolves even with checkout.guess=false, and still errors on a genuinely missing branch. Full suite: 3197 passed, 87.54% coverage.

git-checkout:REF failed with 'not found even after fetch' for branches
that exist on a remote but were never checked out locally. git's own
DWIM can fail to fire (checkout.guess=false, FETCH_HEAD-only fetch).

Resolve it explicitly: when checkout fails as pathspec, find the single
remote carrying refs/remotes/<remote>/REF and create the local tracking
branch via 'checkout -b REF --track <remote>/REF'. Error on >1 match.

Co-Authored-By: Max <noreply>
@fdaviddpt fdaviddpt merged commit eaccb3c into master Jun 1, 2026
12 checks passed
@fdaviddpt fdaviddpt deleted the fix/git-checkout-remote-only-277 branch June 1, 2026 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

git-checkout fails on remote-only branches ("not found even after fetch")

1 participant