Skip to content

Commit 7b9b476

Browse files
AliSoftwareclaude
andcommitted
Reset to FETCH_HEAD rather than the remote-tracking ref
`git fetch origin <branch>` always writes `FETCH_HEAD`, but it only updates `refs/remotes/origin/<branch>` when the remote's configured fetch refspec covers that branch. With the default `+refs/heads/*:refs/remotes/origin/*` that Buildkite sets up, the two are equivalent — but on a clone whose refspec was narrowed after `origin/<branch>` already existed, the fetch leaves that ref stale and `reset --hard "origin/$BRANCH_NAME"` silently lands on the old commit: exactly the failure this script is meant to prevent, reintroduced through the back door. Resetting to `FETCH_HEAD` removes the dependency on the refspec entirely — it is whatever the line above just fetched. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent a7f2b3f commit 7b9b476

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

.buildkite/commands/checkout-release-branch.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ git fetch origin "$BRANCH_NAME"
1212
git checkout "$BRANCH_NAME"
1313
# Buildkite can reuse a working copy where "$BRANCH_NAME" was left at an older commit by a previous job,
1414
# so force the local branch to the fetched commit. `reset --hard` rather than
15-
# `git pull`, to avoid merging if the two diverged.
16-
git reset --hard "origin/$BRANCH_NAME"
15+
# `git pull`, to avoid merging if the two diverged; `FETCH_HEAD` rather than
16+
# `origin/$BRANCH_NAME`, which `git fetch <branch>` only updates opportunistically.
17+
git reset --hard FETCH_HEAD

0 commit comments

Comments
 (0)