{"record":{"id":"f5c1cc2c5616b3d5","repo":"angular/angular-cli","slug":"repository-is-not-clean-update-changes-will-be-mi","errorCode":null,"errorMessage":"Repository is not clean. Update changes will be mixed with pre-existing changes.","messagePattern":"Repository is not clean\\. Update changes will be mixed with pre-existing changes\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/angular/cli/src/commands/update/cli.ts","lineNumber":142,"sourceCode":"        type: 'boolean',\n        alias: ['C'],\n        default: false,\n      })\n      .middleware((argv) => {\n        if (argv.name) {\n          argv['migrate-only'] = true;\n        }\n\n        // eslint-disable-next-line @typescript-eslint/no-explicit-any\n        return argv as any;\n      })\n      .check(({ packages, 'allow-dirty': allowDirty, 'migrate-only': migrateOnly }) => {\n        const { logger } = this.context;\n\n        // This allows the user to easily reset any changes from the update.\n        if (packages?.length && !checkCleanGit(this.context.root)) {\n          if (allowDirty) {\n            logger.warn(\n              'Repository is not clean. Update changes will be mixed with pre-existing changes.',\n            );\n          } else {\n            throw new CommandModuleError(\n              'Repository is not clean. Please commit or stash any changes before updating.',\n            );\n          }\n        }\n\n        if (migrateOnly) {\n          if (packages?.length !== 1) {\n            throw new CommandModuleError(\n              `A single package must be specified when using the 'migrate-only' option.`,\n            );\n          }\n        }\n\n        return true;","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular/cli/src/commands/update/cli.ts#L124-L160","documentation":"Before `ng update` modifies packages it checks that the git working tree is clean via checkCleanGit. If it is dirty and the user did not pass --allow-dirty, the update is aborted with a CommandModuleError; if --allow-dirty was passed, this warning is logged instead, cautioning that the CLI's changes will be intermingled with the user's uncommitted work.","triggerScenarios":"Running `ng update <packages>` (with packages specified and not migrate-only) while `git status` reports uncommitted changes, and either (a) throwing when --allow-dirty is absent, or (b) warning when --allow-dirty is present.","commonSituations":"Forgetting to commit or stash WIP before updating; CI or scripts running updates in dirty checkouts; developers intentionally using --allow-dirty for quick experiments.","solutions":["Commit or stash all changes: `git stash` (or `git add -A && git commit -m \"wip\"`) before running ng update.","Re-run the update after the tree is clean; use `git stash pop` afterwards to restore WIP.","If mixing is intentional and understood, pass `--allow-dirty` to proceed past the check (accepting the warning).","Create a safety branch first: `git checkout -b pre-update-backup` before updating a dirty tree."],"exampleFix":"// before\ngit status            # dirty\nng update @angular/core\n// after\ngit add -A && git commit -m \"wip\"\nng update @angular/core","handlingStrategy":"validation","validationCode":"import { execSync } from 'node:child_process';\nconst status = execSync('git status --porcelain', { cwd: projectRoot }).toString().trim();\nif (status) {\n  throw new Error('Working tree not clean. Commit or stash before `ng update`.');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await ngUpdate(['@angular/core']);\n} catch (e) {\n  if (String(e.message).includes('Repository is not clean')) {\n    execSync('git stash');\n    await ngUpdate(['@angular/core']);\n    execSync('git stash pop');\n  }\n}","preventionTips":["Always commit or stash before running ng update.","Add `git status --porcelain` checks to update scripts/CI pipelines.","Use a dedicated branch or worktree for upgrades.","Only pass --allow-dirty when you fully accept mixed diffs."],"tags":["git","update","angular-cli","safety-check"],"backgroundTag":"dirty-git-working-tree","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}