dbt Commands Cheat Sheet

IntermediateLast updated: 2026-04-09 • 5 sections

Complete reference for dbt CLI commands, Jinja macros, model selection syntax, and project configuration. Covers dbt Core and dbt Cloud.

Core CLI Commands

CommandDescriptionCommon Flags
dbt runExecute all models--select model_name, --full-refresh, --target prod
dbt testRun all tests--select model_name, --store-failures
dbt buildRun + test + snapshot + seed (recommended)--select +model_name+, --full-refresh
dbt compileCompile SQL without executing--select model_name
dbt seedLoad CSV files from /seeds into warehouse--select seed_name, --full-refresh
dbt snapshotExecute snapshot models (SCD)--select snapshot_name
dbt docs generateGenerate documentation site(no common flags)
dbt docs serveServe docs on localhost:8080--port 8081
dbt source freshnessCheck source data freshness--select source:source_name
dbt cleanDelete target/ and packages/ dirs(no flags)
dbt depsInstall packages from packages.yml(no flags)
dbt debugTest connection and config(no flags)

Node Selection Syntax

SelectorMeaningExample
model_nameSingle modeldbt run --select my_model
+model_nameModel and all upstream depsdbt run --select +stg_orders
model_name+Model and all downstream depsdbt run --select stg_orders+
+model_name+Model + all upstream + downstreamdbt build --select +dim_customers+
tag:tag_nameAll models with tagdbt run --select tag:daily
path:models/stagingAll models in directorydbt run --select path:models/staging
source:src_nameA source and related modelsdbt source freshness --select source:raw
@model_nameModel + parents + children + children's parentsdbt run --select @fct_orders
--excludeExclude from selectiondbt run --select staging --exclude stg_legacy

Jinja & Macros

-- Reference another model
SELECT * FROM {{ ref('stg_customers') }}

-- Reference a source
SELECT * FROM {{ source('raw', 'orders') }}

-- Config block in model
{{ config(
    materialized='incremental',
    unique_key='order_id',
    on_schema_change='sync_all_columns'
) }}

-- Incremental filter
{% if is_incremental() %}
  WHERE updated_at > (SELECT MAX(updated_at) FROM {{ this }})
{% endif %}

-- Conditional logic
{% if target.name == 'prod' %}
  {{ config(materialized='table') }}
{% else %}
  {{ config(materialized='view') }}
{% endif %}

-- Loop / dynamic SQL
{% set payment_methods = ['credit_card', 'bank_transfer', 'gift_card'] %}
{% for method in payment_methods %}
  SUM(CASE WHEN payment_method = '{{ method }}' THEN amount END) AS {{ method }}_amount
  {% if not loop.last %},{% endif %}
{% endfor %}

Materializations

TypeWhen to UseRebuild Behavior
viewLightweight models, low compute, always freshRecreated as a SQL view on every run
tableFinal/reporting models, heavy joins, need performanceFull drop and rebuild on every run
incrementalLarge fact tables, append/merge new data onlyOnly processes new rows (with is_incremental filter)
ephemeralDRY helper CTEs, no warehouse object neededInjected as CTE into downstream models
snapshotTrack slowly changing dimensions (SCD Type 2)Compares and captures changes over time

Project Structure Best Practices

  • Organize models in layers: staging/ → intermediate/ → marts/ (facts + dimensions)
  • Prefix staging models with stg_, intermediate with int_, facts with fct_, dimensions with dim_
  • One staging model per source table — no joins, only renaming and casting
  • Use sources (not hardcoded table names) for all raw data references
  • Add schema.yml tests for every model: unique, not_null on primary keys minimum
  • Use tags for orchestration grouping: tag:hourly, tag:daily, tag:weekly
  • Keep incremental models simple — use unique_key for merge logic
  • Set +materialized: view in dbt_project.yml for staging, table for marts

Frequently Asked Questions

What is the difference between dbt run and dbt build?

dbt run only executes model SQL. dbt build runs models AND tests AND seeds AND snapshots in dependency order. Use dbt build as your default — it ensures tests run immediately after each model, catching issues early.

How do incremental models work in dbt?

Incremental models only process new or changed rows instead of rebuilding the entire table. Use the is_incremental() macro to add a WHERE filter that selects only rows newer than the latest data in the target table. Use --full-refresh to force a complete rebuild when schema changes.

What does the + symbol mean in dbt select syntax?

The + prefix means "include all upstream dependencies" (+model runs the model and everything it depends on). The + suffix means "include all downstream dependents" (model+ runs the model and everything that depends on it). Combine both for the full lineage: +model+.

Related Cheat Sheets

Snowflake SQL Cheat SheetApache Airflow Cheat Sheet
← All Cheat Sheets