I am trying to both upgrade my Flutter SDK and also change my Flutter channel to master
, but I encounter the following error:
git: error: Your local changes to the following files would be overwritten by checkout:
git: examples/catalog/android/build.gradle
git: examples/catalog/android/gradle/wrapper/gradle-wrapper.properties
git: packages/flutter_tools/gradle/flutter.gradle
git: Please commit your changes or stash them before you switch branches.
git: Aborting
Switching channels failed with error code 1.
Why does this happen and how do fix this?
These commands executed from the Flutter install directory should get you back to a working state
git clean -xfd
git stash save --keep-index
git stash drop
git pull
flutter doctor
Now flutter upgrade
, flutter channel ...
, ... should work fine again.
https://github.com/flutter/flutter/wiki/Workarounds-for-common-issues#flutter-installation-corrupted
This occurs because the files have been changed locally. This means that the version you have on your machine is different from the one on GitHub.
The easiest way to fix this is using --force
:
flutter upgrade --force
This will override any of the mismatched files. Make sure that you have no progress that would be lost by this (e.g. when you are working on a PR for flutter
).
Another way of resolving this is to delete the files from your device and then execute flutter upgrade
. This will resolve the Git error because it will just fetch the files from the internet again.
To do this head to your Flutter directory and remove the files. E.g. if your Flutter SDK directory was F:/data/flutter
, you would need to remove the following files:
F:/data/flutter/examples/catalog/android/build.gradle
F:/data/flutter/examples/catalog/android/gradle/wrapper/gradle-wrapper.properties
F:/data/flutter/packages/flutter_tools/gradle/flutter.gradle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With