denoland/deno · error

Git repository has uncommitted changes. Use --allow-dirty to

Error message

Git repository has uncommitted changes. Use --allow-dirty to pack anyway.
{}

What it means

`deno pack` refuses to build a package tarball when the git working tree has uncommitted changes, unless `--allow-dirty` is passed. This guarantees the packed artifact corresponds to a reproducible, committed state rather than ephemeral local edits (mirrors `cargo package` / `npm version` hygiene). The dirty file list is appended to the message.

Source

Thrown at cli/tools/pack/mod.rs:54

use extensions::media_type_extension;
use npm_tarball::create_npm_tarball;
use npm_tarball::default_tarball_filename;
use package_json::generate_package_json;
use unfurl::unfurl_specifiers;

pub async fn pack(
  flags: Arc<Flags>,
  pack_flags: PackFlags,
) -> Result<(), AnyError> {
  let cli_factory = CliFactory::from_flags(flags);
  let cli_options = cli_factory.cli_options()?;

  // Check if git repository is clean (unless --allow-dirty)
  if !pack_flags.allow_dirty
    && let Some(dirty) =
      crate::util::git::check_if_git_repo_dirty(cli_options.initial_cwd()).await
  {
    bail!(
      "Git repository has uncommitted changes. Use --allow-dirty to pack anyway.\n{}",
      dirty
    );
  }

  // Get package configs
  let mut packages = cli_options.start_dir.jsr_packages_for_publish();
  if packages.is_empty() {
    match cli_options.start_dir.member_deno_json() {
      Some(deno_json) => {
        let Some(name) = deno_json.json.name.clone() else {
          bail!(
            "Missing 'name' field in '{}'. Add a package name like:\n  {{\n    \"name\": \"@scope/package-name\",\n    ...\n  }}",
            deno_json.specifier
          );
        };
        if deno_json.json.version.is_none() {
          bail!(

View on GitHub (pinned to 9ad36f7a2c)

Solutions

  1. Commit or stash the changes, then re-run `deno pack` (most common correct fix).
  2. If the changes are intentional for this pack, re-run with `deno pack --allow-dirty`.
  3. Check `git status` first to catch unintended dirty files (e.g. build artifacts) and add them to .gitignore.

Example fix

# before
deno pack
# after
git commit -am "chore: bump version" && deno pack
# or, deliberately:
deno pack --allow-dirty
Defensive patterns

Strategy: validation

Validate before calling

#!/usr/bin/env bash
# gate packing on a clean tree
[ -z "$(git status --porcelain)" ] || { echo "dirty tree; commit first"; exit 1; }
deno pack

Prevention

When it happens

Trigger: Running `deno pack` in a git repository where `check_if_git_repo_dirty` reports modifications: edited/staged/untracked files, without `--allow-dirty`.

Common situations: Bumping the version in deno.json and running `deno pack` before committing; generating README/LICENSE files just before packing; switching branches with leftover changes.

Related errors


AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20). Data as JSON: /api/errors/c96965d7716c8ed1. Report an issue: GitHub.