Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Version Control with Git and GitHub  ›  Lesson

What a Flutter Repo Should Track

Git 12 minA Flutter repository tracks source, configuration and the pubspec lock file, while generated folders like build and .dart_tool and any secrets are kept out with .gitignore.

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/ and assets/: 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/ and web/: 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 by flutter pub get.
  • Editor and machine files, and FVM's local .fvm folder.

The .gitignore that flutter create writes already lists most generated paths:

/build/
.dart_tool/
.flutter-plugins-dependencies

Never 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?"

Sorting Sprout's filesStep 1 of 4
  1. lib/plant_tile.dart

    Delete 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.

quick drill

Should the build/ folder be committed?

quick drill

For the Sprout app, what should happen to pubspec.lock?

quick drill

You committed an API key yesterday and deleted the file today. Is the key safe?

quick drill

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: .gitignore does not untrack files that are already committed.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainTrack it or ignore it?

Sort these Sprout files into 'commit' and 'ignore' and justify each: lib/main.dart, pubspec.yaml, pubspec.lock, build/, .dart_tool/, assets/images/fern.png, a file holding a weather API key.