Skip to content

fix: fetch remote branch before checkout in update-copilot-dependency workflow#1088

Merged
stephentoub merged 2 commits intomainfrom
copilot/fix-update-copilot-dependency
Apr 16, 2026
Merged

fix: fetch remote branch before checkout in update-copilot-dependency workflow#1088
stephentoub merged 2 commits intomainfrom
copilot/fix-update-copilot-dependency

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 16, 2026

git push --force-with-lease fails with "stale info" when the workflow re-runs against an already-existing remote branch, because the local remote-tracking ref is never populated before the push.

Changes

  • .github/workflows/update-copilot-dependency.yml: In the existing-branch path, add git fetch origin "$BRANCH" before checkout and reset to origin/$BRANCH (instead of HEAD) so --force-with-lease has accurate tracking info.
# Before
if git rev-parse --verify "origin/$BRANCH" >/dev/null 2>&1; then
  git checkout "$BRANCH"
  git reset --hard HEAD
else
  git checkout -b "$BRANCH"
fi

# After
if git rev-parse --verify "origin/$BRANCH" >/dev/null 2>&1; then
  git fetch origin "$BRANCH"
  git checkout "$BRANCH"
  git reset --hard "origin/$BRANCH"
else
  git checkout -b "$BRANCH"
fi
Original prompt

The "Update @github/copilot Dependency" workflow fails when the remote branch already exists because git push --force-with-lease rejects the push due to stale tracking info.

Failing job: https://github.com/github/copilot-sdk/actions/runs/24489964719/job/71572769209

Error:

! [rejected]  update-copilot-1.0.28 -> update-copilot-1.0.28 (stale info)
error: failed to push some refs to 'https://github.com/github/copilot-sdk'

Root cause: In .github/workflows/update-copilot-dependency.yml, lines 81-86, when the remote branch already exists, the workflow checks it out and resets to HEAD but never fetches the remote branch first. This means --force-with-lease has stale ref info and rejects the push.

Fix: Update the existing-branch path (around lines 81-86) to fetch the remote branch before checking it out:

          if git rev-parse --verify "origin/$BRANCH" >/dev/null 2>&1; then
            git fetch origin "$BRANCH"
            git checkout "$BRANCH"
            git reset --hard "origin/$BRANCH"
          else
            git checkout -b "$BRANCH"
          fi

Key changes:

  1. Add git fetch origin "$BRANCH" to ensure the local remote-tracking ref is current.
  2. Change git reset --hard HEAD to git reset --hard "origin/$BRANCH" so the local branch matches the fetched remote state, allowing --force-with-lease to succeed.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: Please find a solution for this failing job. Use the logs, job definition, and any referenced files where the failure occurred. Keep your response focused on the solution and include code suggestions when appropriate.

Assistant: ## Failing Job Analysis

The job fails at line 100 when pushing the branch:

! [rejected]  update-copilot-1.0.28 -> update-copilot-1.0.28 (stale info)
error: failed to push some refs to 'https://github.com/github/copilot-sdk'

Cause

git push origin "$BRANCH" --force-with-lease fails because the remote branch update-copilot-1.0.28 already exists, but the local checkout doesn't have up-to-date tracking info for it. On lines 81–86, when the branch already exists remotely, the workflow does git checkout "$BRANCH" and git reset --hard HEAD, but it never fetches the remote branch first. This means --force-with-lease sees stale ref info and rejects the push.

Solution

Fetch the remote branch before checking it out so the local ref matches the remote, allowing --force-with-lease to work correctly. Update the workflow at line 81:

          if git rev-parse --verify "origin/$BRANCH" >/dev/null 2>&1; then
            git fetch origin "$BRANCH"
            git checkout "$BRANCH"
            git reset --hard "origin/$BRANCH"
          else
            git checkout -b "$BRANCH"
          fi

Key changes:

  1. git fetch origin "$BRANCH" — ensures the local remote-tracking ref is current.
  2. git reset --hard "origin/$BRANCH" — resets to the fetched remote state (not just local HEAD), so subsequent --force-with-lease has the correct base.

This ensures the push won't be rejected due to stale tracking information when the branch already exists from a previous run.

User: Create a PR to fix it

Assistant: I've started creating a pull request to fix the workflow. The coding agent is working on updating .github/workflows/update-copilot-dependency.yml to fetch the remote branch before checkout, which will resolve the --force-with-lease stale info rejection. I'll share the PR link once it's ready.

This pull request was created from Copilot chat.

…ale info error

Agent-Logs-Url: https://github.com/github/copilot-sdk/sessions/f1827486-b704-48bd-851e-bd6584dd6ae7

Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix workflow to fetch remote branch before checkout fix: fetch remote branch before checkout in update-copilot-dependency workflow Apr 16, 2026
Copilot AI requested a review from stephentoub April 16, 2026 03:26
@stephentoub stephentoub marked this pull request as ready for review April 16, 2026 04:03
@stephentoub stephentoub requested a review from a team as a code owner April 16, 2026 04:03
Copilot AI review requested due to automatic review settings April 16, 2026 04:03
@stephentoub stephentoub enabled auto-merge April 16, 2026 04:03
@stephentoub stephentoub disabled auto-merge April 16, 2026 04:04
@stephentoub stephentoub merged commit a6662b7 into main Apr 16, 2026
12 checks passed
@stephentoub stephentoub deleted the copilot/fix-update-copilot-dependency branch April 16, 2026 04:04
Copy link
Copy Markdown
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

Fixes re-run failures in the “Update @github/copilot Dependency” workflow where git push --force-with-lease can be rejected due to stale/missing remote-tracking information for an already-existing remote branch.

Changes:

  • Fetch the target remote branch before checkout in the existing-branch path.
  • Reset the local branch to origin/$BRANCH instead of HEAD when the remote branch is detected.
Show a summary per file
File Description
.github/workflows/update-copilot-dependency.yml Attempts to ensure up-to-date remote-tracking refs before force-with-lease pushes during dependency update PR automation.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 2

Comment on lines 81 to +82
if git rev-parse --verify "origin/$BRANCH" >/dev/null 2>&1; then
git fetch origin "$BRANCH"
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

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

git rev-parse --verify "origin/$BRANCH" only checks for a local remote-tracking ref. On a fresh Actions checkout this ref typically won’t exist for non-default branches, so this condition can still be false even when the remote branch exists—meaning the new git fetch origin "$BRANCH" never runs and --force-with-lease can remain stale. Consider checking remote existence via git ls-remote --exit-code --heads origin "$BRANCH" (or attempting an explicit refspec fetch and branching on its exit code), then fetching +refs/heads/$BRANCH:refs/remotes/origin/$BRANCH to ensure the tracking ref is populated/updated.

Suggested change
if git rev-parse --verify "origin/$BRANCH" >/dev/null 2>&1; then
git fetch origin "$BRANCH"
if git ls-remote --exit-code --heads origin "$BRANCH" >/dev/null 2>&1; then
git fetch origin "+refs/heads/$BRANCH:refs/remotes/origin/$BRANCH"

Copilot uses AI. Check for mistakes.
Comment on lines 83 to +84
git checkout "$BRANCH"
git reset --hard HEAD
git reset --hard "origin/$BRANCH"
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

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

git reset --hard "origin/$BRANCH" will discard the dependency/codegen changes produced by the earlier workflow steps (since this runs after the update/format steps). If the intent is only to refresh remote-tracking info for --force-with-lease, avoid a hard reset here; alternatively stash changes before switching/resetting and re-apply them, or move the branch checkout/reset logic earlier (before modifications are made).

Copilot uses AI. Check for mistakes.
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.

3 participants