What a Flutter Repo Should Track
A fresh Flutter project already has dozens of files, and running it creates hundreds more. Commit them all and every clone is bloated and full of conflicts; commit too few and a teammate's copy will not build. The rule for choosing is short.
The rule
Track what you write, ignore what the tools rebuild, never commit secrets.
Track (the project is made of these):
lib/,test/andassets/: your code, tests and bundled files.pubspec.yaml: the app's name, dependencies, assets and fonts.pubspec.lock: the exact package versions resolved. For an app, commit it so every machine builds with the same versions.- Platform folders such as
android/,ios/andweb/: they hold settings like app icons and permissions that you edit. analysis_options.yaml,README.md, and the FVM config if you pinned a version.
Ignore (the tools recreate these):
build/: compiled output..dart_tool/: package and tool caches, rebuilt byflutter pub get.- Editor and machine files, and FVM's local
.fvmfolder.
The .gitignore that flutter create writes already lists most generated paths:
/build/
.dart_tool/
.flutter-plugins-dependenciesNever commit secrets such as API keys or signing keystores. Git keeps every version forever, so a key committed once and deleted later is still in the history.
The shortcut
For each file, ask: "If I deleted it, could a command bring it back?"
lib/plant_tile.dartDelete it and no command recreates your code. Track.
The trap is adding a folder to .gitignore after it was already committed. Git keeps tracking files it already knows; you must also remove them from the index with git rm --cached.
Drills
Answer fast — trust the rule.
Should the build/ folder be committed?
For the Sprout app, what should happen to pubspec.lock?
You committed an API key yesterday and deleted the file today. Is the key safe?
You add .dart_tool/ to .gitignore, but Git still shows changes inside it. Why?
Remember
- Track what you write, ignore what the tools rebuild, never commit secrets.
- Ask: could a command bring it back? Yes means ignore (except the lock file).
- Trap:
.gitignoredoes not untrack files that are already committed.
