Skip to content

fix: fetch before merging in Update from Default Branch#111

Merged
pol-rivero merged 1 commit into
pol-rivero:mainfrom
guplem:fix/fetch-before-update-from-main
Mar 27, 2026
Merged

fix: fetch before merging in Update from Default Branch#111
pol-rivero merged 1 commit into
pol-rivero:mainfrom
guplem:fix/fetch-before-update-from-main

Conversation

@guplem

@guplem guplem commented Mar 27, 2026

Copy link
Copy Markdown

Summary

Closes #110

  • Adds await this.props.dispatcher.fetch(repository, FetchType.UserInitiatedTask) before the mergeBranch call in updateBranchWithContributionTargetBranch().
  • Makes the method async to allow awaiting the fetch.
  • FetchType was already imported; no additional imports needed.

Root cause

updateBranchWithContributionTargetBranch() merged directly against the local ref for the default branch without fetching from remote first. If the local ref was stale, git would correctly report "already up to date" relative to the cached local state — even though the remote had new commits.

Test plan

  • Click Branch > Update from Main when the remote default branch has unpulled commits — confirm the fetch runs and the merge succeeds.
  • Click Branch > Update from Main when the branch is genuinely up to date — confirm the app correctly reports "already up to date".

Without a fetch, the operation compared against the stale local ref for
the default branch, causing it to incorrectly report "already up to
date" when remote had unpulled commits.

Fixes pol-rivero#110

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@guplem

guplem commented Mar 27, 2026

Copy link
Copy Markdown
Author

Additional context

This is a known issue in the upstream desktop/desktop repo: desktop/desktop#19559 — filed November 2024, still open. Multiple users describe the identical workaround (switch to main → fetch → switch back → "Update from Main").

A GitHub Desktop team member responded saying the behavior is intentional and pointed users to the manual Fetch button. The community is unhappy with that answer, with comments as recent as January 2026 still expressing frustration.

Why silently fetch (no popup)

The action is named "Update from Main" — the implicit contract is "give me the latest from main", which requires a fetch. The mental model doesn't include "...but only if I've already fetched recently". Adding a confirmation dialog or a "fetch + update" / "update only" split would add friction to every use of a very common action, for the benefit of a narrow edge case (offline, metered connection). Background fetch already runs silently — this should be consistent with that.

If the fetch fails, _fetch surfaces the error through the existing error path. No extra dialog needed.

@ignatremizov

ignatremizov commented Mar 27, 2026

Copy link
Copy Markdown

this is big, too many times I merged into a stale main/develop branch - one note shouldn't it also pull fast-forward? because fetch updates origin/main, not necessarily also local main

@pol-rivero

Copy link
Copy Markdown
Owner

@guplem That's a nice and clean fix, thanks!

@ignatremizov

one note shouldn't it also pull fast-forward?

Yeah, I was thinking the same thing but then saw that performFetch also calls fastForwardBranches for some reason. This comes from upstream, so I'm not going to touch it, but naming this method "fetch" isn't great.

@pol-rivero pol-rivero merged commit 1f274dc into pol-rivero:main Mar 27, 2026
18 checks passed
@guplem

guplem commented Mar 28, 2026

Copy link
Copy Markdown
Author

I actually didn't realize the fast-forward was being done inside the fetch. I actually lean towards not liking it (I didn't think local files/branches should be altered without user intent) but I can live with that

@pol-rivero

Copy link
Copy Markdown
Owner

@guplem A possible alternative would be to merge the remote branch (for example origin/main) instead of the local (e.g. main) branch after fetching (without pulling). This would avoid altering the local main branch.
If that's easy to do, feel free to write a follow-up PR, I think that would be an improvement.

@ignatremizov

ignatremizov commented Mar 28, 2026

Copy link
Copy Markdown

@pol-rivero that would create a new branch, origin/main is the "branch on origin", when merging you always merge "locally" then push to a remote branch on origin.

What I think should be instead is a configuration toggle - when "merging to main" - to 1. auto-fetch-fast-forward-pull (default, current behaviour, clean history), or 2. merge-then-fetch-and-pull (would cause an additional merge commit "merge main to origin/main" when pushing to origin/main - looks off but might be someone's workflow for making PRs to an upstream project from a local main branch, for example)

EDIT: Ignore me, see discussion below

@pol-rivero

Copy link
Copy Markdown
Owner

@ignatremizov

that would create a new branch, origin/main is the "branch on origin", when merging you always merge "locally" then push to a remote branch on origin.

I'm not sure if I follow. You can absolutely do git merge origin/main without creating a local branch.

@pol-rivero

Copy link
Copy Markdown
Owner

Here's what I meant:

2026-03-28.12-47-14.mp4

@ignatremizov

Copy link
Copy Markdown

Right - sorry, I was mixed up for a second about direction. git merge merges the commits pointed to by origin/main into the currently checked out branch, not the other way

Ok, so if the goal is to "Update from Main" meaning the remote main, I propose to change the label to do "Update from Origin Main" (or from whatever remote is configured) so that it's the actual git merge origin/main and not fetch, pull fast forward main, git merge main - this would be better than implicitly fast-forwarding main as part of a routine branch task

@pol-rivero

pol-rivero commented Mar 28, 2026

Copy link
Copy Markdown
Owner

Exactly. The only note I would add is that the git fetch is still required to make sure the origin/main pointer is up-to-date. The only difference vs. what we currently have in this PR is that we would not fast-forward the local main branch.

@guplem

guplem commented Mar 29, 2026

Copy link
Copy Markdown
Author

Follow-up PR implementing the improvement suggested by @pol-rivero: #113

It merges origin/main (the remote tracking branch) directly instead of the local main, and fetches without fast-forwarding local branches. The menu label is also updated to show the remote ref (e.g. "Update from origin/main").

@guplem guplem deleted the fix/fetch-before-update-from-main branch March 29, 2026 18:17
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.

"Update from Main" reports up-to-date when local main is stale (missing fetch before merge)

3 participants