Fixing `Unknown flutter tag. Abandoning upgrade to avoid destroying local changes. It is recommended to use git directly if not working on an official channel.` when running `flutter upgrade`

This morning, flutter upgrade failed with an error message I have never seen before:

% flutter upgrade
Unknown flutter tag. Abandoning upgrade to avoid destroying local changes. It is recommended to use git directly if not working on an official channel.
anhtuan@macmini flashcards % flutter --version
Flutter 3.13.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision e1e47221e8 (6 weeks ago) • 2023-08-22 21:43:18 -0700
Engine • revision b20183e040
Tools • Dart 3.1.0 • DevTools 2.25.0

I did not use a custom build nor touch the Flutter git repository, so this error is puzzling. Just to be sure, I forcefully switched to stable and ran the upgrade again. Unfortunately I got the same error.

% flutter channel stable
Switching to flutter channel 'stable'...

Upgrading engine...
Successfully switched to flutter channel 'stable'.
To ensure that you're on the latest build from this channel, run 'flutter upgrade'
anhtuan@macmini flashcards % flutter --version     

┌─────────────────────────────────────────────────────────┐
│ A new version of Flutter is available!                  │
│                                                         │
│ To update to the latest version, run "flutter upgrade". │
└─────────────────────────────────────────────────────────┘
Flutter 3.13.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision e1e47221e8 (6 weeks ago) • 2023-08-22 21:43:18 -0700
Engine • revision b20183e040
Tools • Dart 3.1.0 • DevTools 2.25.0
anhtuan@macmini flashcards % flutter upgrade       
Unknown flutter tag. Abandoning upgrade to avoid destroying local changes. It is recommended to use git directly if not working on an official channel.

In verbose mode, I don't get much more information either:

% flutter upgrade -v
[   +4 ms] executing: sw_vers -productName
[  +14 ms] Exit code 0 from: sw_vers -productName
[        ] macOS
[        ] executing: sw_vers -productVersion
[  +14 ms] Exit code 0 from: sw_vers -productVersion
[        ] 13.5.2
[        ] executing: sw_vers -buildVersion
[  +16 ms] Exit code 0 from: sw_vers -buildVersion
[        ] 22G91
[        ] executing: uname -m
[   +3 ms] Exit code 0 from: uname -m
[        ] arm64
[   +4 ms] executing: sysctl hw.optional.arm64
[  +12 ms] Exit code 0 from: sysctl hw.optional.arm64
[        ] hw.optional.arm64: 1
[  +59 ms] executing: git tag --points-at HEAD
[  +13 ms] Exit code 0 from: git tag --points-at HEAD
[   +1 ms] executing: git describe --match *.*.* --long --tags HEAD
[  +11 ms] Exit code 128 from: git describe --match *.*.* --long --tags HEAD
[        ] fatal: No names found, cannot describe anything.
[        ] Could not interpret results of "git describe": 
[   +1 ms] executing: [/Users/anhtuan/flutter/] git fetch --tags
[ +763 ms] executing: [/Users/anhtuan/flutter/] git rev-parse --verify @{upstream}
[  +14 ms] ead455963c12b453cdb2358cad34969c76daf180
[        ] executing: [/Users/anhtuan/flutter/] git tag --points-at ead455963c12b453cdb2358cad34969c76daf180
[  +27 ms] Exit code 0 from: git tag --points-at ead455963c12b453cdb2358cad34969c76daf180
[        ] 3.13.6
[   +5 ms] "flutter upgrade" took 875ms.
[   +3 ms] Unknown flutter tag. Abandoning upgrade to avoid destroying local changes. It is recommended to use git directly if not working on an official channel.
[   +1 ms] 
           #0      throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
           #1      UpgradeCommandRunner.runCommandFirstHalf (package:flutter_tools/src/commands/upgrade.dart:142:9)
           <asynchronous suspension>
           #2      UpgradeCommandRunner.runCommand (package:flutter_tools/src/commands/upgrade.dart:102:7)
           <asynchronous suspension>
           #3      FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1297:27)
           <asynchronous suspension>
           #4      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #5      CommandRunner.runCommand (package:args/command_runner.dart:212:13)
           <asynchronous suspension>
           #6      FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:339:9)
           <asynchronous suspension>
           #7      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #8      FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:285:5)
           <asynchronous suspension>
           #9      run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:115:9)
           <asynchronous suspension>
           #10     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #11     main (package:flutter_tools/executable.dart:90:3)
           <asynchronous suspension>
           
           
[ +214 ms] ensureAnalyticsSent: 195ms
[   +2 ms] Running 0 shutdown hooks
[        ] Shutdown hooks complete
[        ] exiting with code 1

A quick search online leads me to this GitHub ticket. The fix is to run flutter upgrade --force. I did and indeed, it worked!

% flutter upgrade --force
Upgrading Flutter to 3.13.6 from 3.13.1 in /Users/[username]/flutter...
Downloading Darwin arm64 Dart SDK from Flutter engine a794cf2681c6c9fe7b260e0e84de96298dc9c18b...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

100  195M  100  195M    0     0  8278k      0  0:00:24  0:00:24 --:--:-- 13.1M
Building flutter tool...
Resolving dependencies...
Got dependencies.

Upgrading engine...
Downloading android-arm-profile/darwin-x64 tools...                711ms
Downloading android-arm-release/darwin-x64 tools...                388ms
Downloading android-arm64-profile/darwin-x64 tools...              461ms
Downloading android-arm64-release/darwin-x64 tools...              419ms
Downloading android-x64-profile/darwin-x64 tools...                465ms
Downloading android-x64-release/darwin-x64 tools...              1,206ms
Downloading android-x86 tools...                                    3.2s
Downloading android-x64 tools...                                 2,072ms
Downloading android-arm tools...                                 1,936ms
Downloading android-arm-profile tools...                           636ms
Downloading android-arm-release tools...                           459ms
Downloading android-arm64 tools...                               2,265ms
Downloading android-arm64-profile tools...                         745ms
Downloading android-arm64-release tools...                         624ms
Downloading android-x64-profile tools...                           758ms
Downloading android-x64-release tools...                           546ms
Downloading android-x86-jit-release tools...                       921ms
Downloading ios tools...                                           12.7s
Downloading ios-profile tools...                                   15.1s
Downloading ios-release tools...                                    4.5s
Downloading Web SDK...                                              5.9s
Downloading package sky_engine...                                  141ms
Downloading flutter_patched_sdk tools...                           393ms
Downloading flutter_patched_sdk_product tools...                 1,731ms
Downloading darwin-arm64 tools...                                   6.3s
Downloading darwin-x64/FlutterMacOS.framework tools...              4.4s
Downloading darwin-x64/gen_snapshot tools...                       992ms
Downloading darwin-x64-profile/FlutterMacOS.framework tools...      2,347ms
Downloading darwin-x64-profile tools...                            492ms
Downloading darwin-x64-profile/gen_snapshot tools...               826ms
Downloading darwin-x64-release/FlutterMacOS.framework tools...         7.2s
Downloading darwin-x64-release tools...                            963ms
Downloading darwin-x64-release/gen_snapshot tools...             1,714ms
Downloading darwin-arm64/font-subset tools...                    1,129ms

Flutter 3.13.6 • channel stable • https://github.com/flutter/flutter.git
Framework • revision ead455963c (5 days ago) • 2023-09-26 18:28:17 -0700
Engine • revision a794cf2681
Tools • Dart 3.1.3 • DevTools 2.25.0

Running flutter doctor...
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.13.6, on macOS 13.5.2 22G91 darwin-arm64, locale ko-KR)
[!] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.
[!] Xcode - develop for iOS and macOS (Xcode 15.0)
    ✗ Unable to get list of installed Simulator runtimes.
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] VS Code (version 1.82.2)
[✓] Connected device (2 available)
[✓] Network resources

! Doctor found issues in 2 categories.