Skip to content

Add a --force (-f) flag to flutter channel #191262

Description

@vsarnatarodst

Use case

The flutter channel <name> command internally performs a git checkout of the branch corresponding to the target channel inside the SDK repository. If the SDK has local changes to tracked files — most commonly pubspec.lock, which gets regenerated as a side effect of normal Flutter operations (tool recompilation, pub get, cache updates) — the operation fails with:

Switching channels failed
error: Your local changes to the following files would be overwritten by checkout: pubspec.lock
Please commit your changes or stash them before you switch branches.
Aborting.

The problem is that these changes are almost never intentional: they're an artifact of how the tool itself works, not something the developer chose to modify in the SDK. The user asked to switch channels, but ends up facing a raw git error about branches — a concept they never touch directly at the Flutter interface level.

Today the only way to get unstuck is to step outside the Flutter workflow and use git manually in the SDK directory (git checkout -- pubspec.lock, git stash, or git reset --hard). This requires knowing where the SDK lives, understanding which files are tracked, and it's inherently risky: a blind reset --hard can wipe more than intended.

Proposal

Add a --force (-f) flag to flutter channel, with the same semantics it already has in flutter upgrade: force the channel switch by discarding the local SDK changes that would block the checkout.

Key benefits:

  • Interface consistency. flutter upgrade already exposes --force. Aligning flutter channel removes an asymmetry that currently surprises anyone expecting the same behavior across two commands that both manipulate the SDK's git state.
  • Official, documented path. Replaces fragile manual git commands with a supported option, reducing the risk of destructive operations run blindly.
  • Automation and CI. Scripts that switch channels shouldn't have to rely on git workarounds tied to the SDK's internal implementation; a stable flag is far more robust over time.
  • UX. Hides the fact that the SDK is a git repo — an implementation detail users shouldn't need to know about to perform a high-level operation like switching channels.

Ideally, --force would discard only the specific files blocking the checkout, offering a more controlled alternative to a manually executed git reset --hard.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listc: proposalA detailed proposal for a change to Flutterteam-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-toolTriaged by Flutter Tool team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions