A professional terminal/CLI tool built with Node.js that simplifies initializing projects with official .gitignore templates from the GitHub gitignore repository.
Stop manually searching and copy-pasting .gitignore contentβfetch and save them directly from your terminal!
- Fetch .gitignore π‘οΈ
- Table of Contents
- π Features
- π¦ Installation
- π οΈ Usage
- π§ͺ Local Development & Testing
- π§ͺ Running Tests
- ποΈ Architecture
- π€ Contributing
- π License
- π Troubleshooting
- π Development Workflow
- Dynamic Fetching: Pulls the latest templates directly from the official GitHub repository.
- Multiple Templates: Combine multiple
.gitignoretemplates (e.g.,Node,Python,Visual Studio Code). - Caching: Local caching of templates and list for faster access and offline use.
- Safety: Prevents accidental overwriting of existing
.gitignorefiles unless forced. - Append Mode: Easily add new rules to your existing
.gitignore. - Directory Support: Target any directory, whether it's your current path or a subproject.
- Rate Limit Handling: Smartly handles GitHub API rate limits and provides clear feedback on when to retry.
To use fetch-gitignore as a global CLI tool, install it via npm:
npm install -g @dileepadev/fetch-gitignoreOr run it instantly using npx:
npx @dileepadev/fetch-gitignore list
npx @dileepadev/fetch-gitignore add NodeTo see all templates available in the official GitHub repository:
fetch-gitignore listTo create a new .gitignore file for your project:
fetch-gitignore add <TemplateName>Example: fetch-gitignore add Node
You can pass multiple template names to merge them into a single .gitignore file:
fetch-gitignore add Node Python Rust| Option | Shorthand | Description | Default |
|---|---|---|---|
--dir <path> |
-d |
Target directory where .gitignore will be saved. |
. |
--append |
-a |
Append content to an existing .gitignore file. |
false |
--force |
-f |
Force overwrite an existing .gitignore file. |
false |
--no-cache |
- | Bypass local cache and fetch directly from GitHub. | false |
--help |
-h |
Display help information. | - |
--version |
-V |
Display the version number. | - |
Templates and the template list are cached locally (usually in ~/.fetch-gitignore-cache) for 24 hours.
You can customize the Time-To-Live (TTL) using an environment variable:
# Set cache to expire after 1 hour (3600 seconds)
export FETCH_GITIGNORE_CACHE_TTL=3600To disable caching entirely, set it to 0:
export FETCH_GITIGNORE_CACHE_TTL=0This guide explains how to test fetch-gitignore locally before publishing to npm.
- Node.js β₯ 18
- npm β₯ 9
Check your version:
node -v
npm -vFrom the project root:
npm installBuild the TypeScript sources:
npm run buildThis simulates installing the package globally via npm install -g.
npm linkThis creates a global symlink so you can run:
fetch-gitignorefrom anywhere on your system.
Move to any test directory:
mkdir test-cli
cd test-cliThen try:
fetch-gitignore listfetch-gitignore add Nodefetch-gitignore add Python --appendfetch-gitignore add Node --forcefetch-gitignore add Node Python Reactfetch-gitignore add Node --dir ./backendfetch-gitignore list --no-cache
fetch-gitignore add Node --no-cacheIf you donβt want to use npm link, you can run the CLI directly:
node dist/bin/index.js listor
node dist/bin/index.js add NodeTo simulate a real npm installation:
npm packThis generates a .tgz file like:
dileepadev-fetch-gitignore-1.0.2.tgz
Then install it globally:
npm install -g ./dileepadev-fetch-gitignore-1.0.2.tgzNow test it as if it were published.
To remove the global symlink:
npm unlink -g @dileepadev/fetch-gitignoreThis project uses Vitest for unit and integration testing.
npm testnpm run test:watchnpm run test:coverage| Test File | Module | Description |
|---|---|---|
tests/utils.test.ts |
resolveDirectory, mergeTemplates |
Directory resolution, template merging, edge cases |
tests/logger.test.ts |
logSuccess, logError, logInfo |
Stdout/stderr routing, message content |
tests/fileManager.test.ts |
writeGitignore |
Create, overwrite, append, conflict errors |
tests/cache.test.ts |
saveToCache, getFromCache |
Save/load, TTL logic, env var overrides |
tests/fetcher.test.ts |
fetchTemplate, listTemplates |
Mocked HTTP: success, 404, rate limits, response parsing |
tests/cli.test.ts |
CLI binary | --help, --version, subcommands, error handling |
- TypeScript: Strict, type-safe codebase compiled to ESM.
- Commander.js: Powering the CLI command and argument parsing.
- Node-Fetch: Used to retrieve template data from GitHub APIs.
- Chalk & Ora: Creating a beautiful, interactive terminal experience.
- File System (fs): Reliable management of
.gitignorefiles and local caching. - Vitest: Fast, TypeScript-native test framework for unit and integration tests.
Contributions are welcome! Please check our CONTRIBUTING.md for guidelines on how to get started.
Distributed under the MIT License. See LICENSE for more information.
Make sure npm link ran successfully. You can verify it with:
which fetch-gitignoreEnsure your CLI entry file is executable:
chmod +x dist/bin/index.jsDuring development:
- Edit code
- Run
npm run build - Run
fetch-gitignore - Test behavior
- Repeat
Because npm link creates a symlink, changes apply immediately β no reinstall required.