{"id":30020833,"url":"https://github.com/itsnickbarry/exec-staged","last_synced_at":"2026-05-19T10:31:34.503Z","repository":{"id":300836441,"uuid":"998519809","full_name":"ItsNickBarry/exec-staged","owner":"ItsNickBarry","description":"Run commands against the current git index 🏟️","archived":false,"fork":false,"pushed_at":"2025-06-23T22:15:04.000Z","size":305,"stargazers_count":0,"open_issues_count":6,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-07-26T10:56:19.717Z","etag":null,"topics":["commit","exec","git","hook","lint","lint-staged","pre-commit","staged","wow"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ItsNickBarry.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-08T19:30:14.000Z","updated_at":"2025-06-23T22:15:07.000Z","dependencies_parsed_at":"2025-06-23T21:53:27.030Z","dependency_job_id":null,"html_url":"https://github.com/ItsNickBarry/exec-staged","commit_stats":null,"previous_names":["itsnickbarry/exec-staged"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/ItsNickBarry/exec-staged","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ItsNickBarry%2Fexec-staged","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ItsNickBarry%2Fexec-staged/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ItsNickBarry%2Fexec-staged/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ItsNickBarry%2Fexec-staged/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ItsNickBarry","download_url":"https://codeload.github.com/ItsNickBarry/exec-staged/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ItsNickBarry%2Fexec-staged/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269005891,"owners_count":24343408,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-06T02:00:09.910Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["commit","exec","git","hook","lint","lint-staged","pre-commit","staged","wow"],"created_at":"2025-08-06T02:16:01.089Z","updated_at":"2026-05-19T10:31:34.497Z","avatar_url":"https://github.com/ItsNickBarry.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Exec Staged\n\nRun commands against files staged in git, ignoring unstaged changes and untracked files.\n\n### Use Cases\n\n- 🧵 Lint new changes before commit.\n- 🧪 Test changes in isolation before commit.\n- ✨ ???\n\n### How it Works\n\n1. Unstaged changes and untracked files are hidden in a git stash. This includes unstaged deletions, which are temporarily restored.\n2. User-configured tasks are run, with staged files passed in according to configuration.\n3. Any changes made by tasks are added to the git index. This includes additions and deletions.\n4. The stashed changes are restored.\n5. If any step fails, the initial state is fully restored.\n\n## Installation\n\nInstall from npm, using your preferred package manager:\n\n```bash\nnpm install --save-dev exec-staged\n```\n\n## Requirements\n\n- Git \u003e= 2.22.0\n\n## Usage\n\n### Run from the CLI\n\nIf an `exec-staged` configuration file is present, it will be loaded by the executable:\n\n```bash\nnpx exec-staged\n```\n\nIf no configuration is present, the executable can still run tasks passed as arguments:\n\n```bash\nnpx exec-staged \"npm test\"\n```\n\n### Run in a Script\n\n```typescript\nimport { execStaged } from 'exec-staged';\n\nconst cwd = process.cwd();\nconst tasks = [`npm test`];\nconst options = { quiet: true };\n\nconst result = await execStaged(cwd, tasks, options);\n\nif (!result) {\n  throw new Error('exec-staged task failed');\n}\n```\n\n### Run in a Pre-Commit Hook\n\n[Husky](https://github.com/typicode/husky) is recommended for handling pre-commit hooks.\n\nInstall Husky:\n\n```bash\nnpm install --save-dev husky\n```\n\nAdd a hook to `.husky/pre-commit`:\n\n```bash\n#!/bin/sh\nnpx exec-staged\n```\n\nRun husky:\n\n```bash\nnpx husky\n```\n\nAdd a `package.json` script to run husky whenever your repository is cloned:\n\n```json\n{\n  \"scripts\": {\n    \"prepare\": \"husky\"\n  }\n}\n```\n\n`exec-staged` will do nothing unless configured. See configuration information below.\n\n## Configuration\n\n`exec-staged` configuration consists of a list of commands to execute against the stage. Each command may be formatted as a plain `string`, or as an object containing additional attributes.\n\nAll [Cosmiconfig-compatible](https://www.npmjs.com/package/cosmiconfig#searchplaces) configuration files are supported.\n\nHere is an example configuration:\n\n```typescript\n// exec-staged.config.ts\nimport type { ExecStagedUserConfig } from 'exec-staged/types';\n\nconst config: ExecStagedUserConfig = [\n  'knip',\n  'knip --production',\n  { task: 'prettier --write $FILES', glob: '*.{js,ts,json,md}' },\n];\n\nexport default config;\n```\n\nPlain commands are run every time, as-is:\n\n\u003c!-- prettier-ignore-start --\u003e\n```typescript\n'knip --production'\n```\n\u003c!-- prettier-ignore-end --\u003e\n\nCommands which include the `$FILES` token are only run if staged files are found, and those files are interpolated into the command in place of the token.\n\n\u003c!-- prettier-ignore-start --\u003e\n```typescript\n'prettier --write $FILES'\n// =\u003e prettier --write new_file.js modified_file.js\n```\n\u003c!-- prettier-ignore-end --\u003e\n\nFile filtering can be customized.\n\nTo filter files by name, add a `glob` filter (defaults to `'**'`):\n\n```typescript\n{ task: 'prettier --write $FILES', glob: '*.{js,ts,json,md}' }\n```\n\nTo filter files by git status, add a `diff` filter (defaults to `'AM'`; see [here](https://git-scm.com/docs/git-status#_short_format)):\n\n```typescript\n{ task: 'prettier --write $FILES', diff: 'A' }\n```\n\nDefining `diff` or `glob` on a task that does not include the `$FILES` token has no effect:\n\n```typescript\n{ task: 'knip', diff: 'NO EFFECT', glob: 'NO EFFECT' }\n```\n\n## Safety Features\n\nBefore running any potentially destructive scripts, `exec-staged` stores all outstanding changes, including untracked files, in a backup stash. If any task fails, or if `exec-staged` is interrupted by an end-process signal (such as via \u003ckbd\u003eCtrl + C\u003c/kbd\u003e), the repository's original state is restored using this stash. Avoid running any tasks that interact with git, especially those that make commits or modify the stash.\n\n### Recovery\n\nIf `exec-staged` fails to exit safely, such as due to power loss or if its process is killed via `SIGKILL`, run the recovery tool to restore your repository to its original state:\n\n```bash\nnpx exec-staged recover\n```\n\nThis will automatically find and apply the backup stash, restore any merge metadata, and clean up leftover artifacts.\n\nTo prevent data loss, `exec-staged` will not run if artifacts from a previous run are present.\n\n## See Also\n\n- [`lint-staged`](https://github.com/lint-staged/lint-staged): the inspiration for `exec-staged`.\n- [`knip`](https://github.com/webpro-nl/knip): a linter that analyzes interactions between files, which is outside of the designed scope of `lint-staged`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitsnickbarry%2Fexec-staged","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitsnickbarry%2Fexec-staged","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitsnickbarry%2Fexec-staged/lists"}