How to Prevent Committing Errors in Flutter to Git?
Create a file called
pre-commit in the
pre-commit file in a text editor and paste the following code:
flutter pub run flutter_lints
if [ $? -ne 0 ]; then
echo "Aborting commit. Fix the linter errors/warnings above and try again."
This script will run the Flutter linter whenever you attempt to commit changes.
Save and close the
pre-commit file executable by running the following command in your terminal:
chmod +x .git/hooks/pre-commit
Now, whenever you try to commit changes, the
pre-commit hook will run the Flutter linter and abort the commit if any errors or warnings are found. This helps ensure that your code follows consistent style guidelines and is free from common issues before committing it to version control.