dbt clean deletes a project’s generated artifacts to restore the repository to a fresh, reproducible state.
dbt clean is a command-line utility that removes the target, dbt_packages, and logs directories from a dbt project, returning the workspace to its original, version-controlled state.
Cleaning eliminates stale compiled SQL, broken dependencies, and local logs that can mask production issues, ensuring deterministic builds across machines and CI pipelines.
The command deletes target/
(compiled models, manifests), dbt_packages/
(packages installed via dbt deps), and logs/
by default, but leaves source-controlled files untouched.
Run dbt clean before switching branches, after upgrading dbt versions or dependencies, and in CI jobs prior to dbt deps and dbt run to guarantee a pristine environment.
From the project root, execute dbt clean
. Optionally combine with dependency installation:
dbt clean && dbt deps && dbt run
dbt iterates over a hard-coded list of directories, verifies their presence, and performs recursive deletion using Python’s shutil.rmtree()
. No database objects are touched.
Yes. Add extra paths under the clean-targets
key in dbt_project.yml
:
clean-targets:
- target
- dbt_packages
- logs
- .pytest_cache
Insert dbt clean as the first step of every CI job so ephemeral containers start with no leftover artifacts, preventing false-positive test results and cache pollution.
Commit clean-targets
to version control, cache only seeds and snapshots, and treat clean as idempotent—run it anytime without fear of data loss.
Deleting untracked data files, forgetting to re-install packages, and assuming clean affects the warehouse schema are frequent mistakes; configure clean-targets
carefully.
Galaxy’s built-in terminal lets you run dbt clean
next to your SQL. The AI copilot detects the command and suggests running dbt deps
afterward, streamlining local resets.
Cleaning ensures that every dbt run starts from the same baseline across developers and pipelines. By deleting generated artifacts, teams avoid "works on my machine" issues, reduce merge conflicts on compiled SQL, and guarantee that dependency changes are fully respected in downstream builds.
No. The command only deletes local folders like target/, dbt_packages/, and logs/. All database objects remain intact.
Yes. Define extra paths under clean-targets in dbt_project.yml to extend what gets removed.
Run it before every branch switch, after dependency upgrades, and at the start of each CI job for reproducible builds.
Galaxy’s SQL editor includes a terminal where you can run dbt clean. The AI copilot recommends follow-up commands like dbt deps, ensuring a smooth workflow.