Skip to content

issue:checkout: fetch remote before checkout when remote already exists#330

Merged
mglaman merged 4 commits intomainfrom
copilot/fix-checkout-fetch-remote
Mar 24, 2026
Merged

issue:checkout: fetch remote before checkout when remote already exists#330
mglaman merged 4 commits intomainfrom
copilot/fix-checkout-fetch-remote

Conversation

Copy link
Contributor

Copilot AI commented Mar 23, 2026

issue:checkout only fetched the remote when it was being newly added. If the remote already existed locally (manually added, or stale from a previous session), no fetch occurred before the checkout attempt, causing git checkout -b <branch> --track <remote>/<branch> to fail with a missing ref error.

Changes

  • Checkout.php: Added git fetch <remote> in the branch where the remote already exists, ensuring local tracking refs are always up-to-date before the checkout. Fetch failure surfaces an explicit error message and exits early.
Remote exists → git fetch <remote>  ← new
             ↓
git checkout -b <branch> --track <remote>/<branch>

The "remote not found" path (via SetupIssueRemoteAction) already fetched after adding — this change closes the gap for the pre-existing remote case.

Original prompt

This section details on the original issue you should resolve

<issue_title>issue:checkout needs to fetch the remote after adding issue fork remote</issue_title>
<issue_description>not sure if issue:setup-remote needs this as well. used issue:checkout and checking out the branch failed because the new remote was not fetched</issue_description>

Comments on the Issue (you are @copilot in this section)


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Copilot AI changed the title [WIP] Fix checkout to fetch remote after adding fork issue:checkout: fetch remote before checkout when remote already exists Mar 23, 2026
Copilot AI requested a review from mglaman March 23, 2026 19:32
@mglaman mglaman requested a review from Copilot March 24, 2026 11:21
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes issue:checkout failing to track a remote branch when the issue fork remote already exists locally by ensuring the remote is fetched before attempting the checkout.

Changes:

  • When the expected remote already exists, run git fetch <remote> before git checkout -b ... --track ....
  • Surface a clear fetch failure message and exit early if the fetch fails.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@mglaman
Copy link
Owner

mglaman commented Mar 24, 2026

@copilot I didn't have the remote setup, can we verify ,SetupIssueRemoteAction does the fetch of the remote as well

Copy link
Contributor Author

Copilot AI commented Mar 24, 2026

@copilot I didn't have the remote setup, can we verify ,SetupIssueRemoteAction does the fetch of the remote as well

Yes — SetupIssueRemoteAction::__invoke() always runs git fetch <remote> unconditionally (lines 46–55), regardless of whether the remote was newly added or already existed. So both paths are covered: newly-added remote (add → fetch) and pre-existing remote (skip add → fetch). No changes needed there.

@mglaman mglaman marked this pull request as ready for review March 24, 2026 16:29
@mglaman mglaman merged commit beca07a into main Mar 24, 2026
9 checks passed
@mglaman mglaman deleted the copilot/fix-checkout-fetch-remote branch March 24, 2026 17:01
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.

issue:checkout needs to fetch the remote after adding issue fork remote

3 participants