gitignore.io API を使って .gitignore ファイルを生成・更新する。プロジェクトの言語・OS・エディタに応じたテンプレートを取得し、プロジェクトルートに .gitignore を作成する。
gitignore.io(toptal)API を利用して .gitignore を生成する。
https://www.toptal.com/developers/gitignore/apiGET /list?format=lines(改行区切り)または ?format=json(JSON)GET /<templates>(カンマ区切りで複数指定)例: GET /node,visualstudiocode,windows → Node.js + VS Code + Windows 用の .gitignore を返す
settings.json の project.language から主要テンプレートを決定する。
project.language | gitignore.io テンプレート |
|---|
javascript | node |
typescript | node |
python | python |
go | go |
rust | rust |
java | java,maven,gradle |
csharp | csharp,visualstudio |
ruby | ruby |
other | ユーザーに確認 |
以下を自動追加する:
visualstudiocode(常時追加)windows, macos, linux を追加ユーザーに追加テンプレートが必要か確認する:
「追加の gitignore テンプレートはありますか?(例: terraform, dotenv, redis)」
不明なテンプレート名が指定された場合、一覧を取得して近い候補を提示する:
curl -sL "https://www.toptal.com/developers/gitignore/api/list?format=lines"
PowerShell の場合:
Invoke-RestMethod "https://www.toptal.com/developers/gitignore/api/list?format=lines"
テンプレートをカンマ区切りで結合し、API から .gitignore の内容を取得する:
curl -sL "https://www.toptal.com/developers/gitignore/api/<templates>" -o .gitignore
PowerShell の場合:
$templates = "node,visualstudiocode,windows"
$content = Invoke-RestMethod "https://www.toptal.com/developers/gitignore/api/$templates"
Set-Content -Path ".gitignore" -Value $content -NoNewline
API 生成コンテンツの末尾に、プロジェクト共通のルールとプロジェクト固有のルールを追加する:
# === Worktree (always excluded) ===
.worktrees/
# === Project-specific rules ===
.env
.env.*
!.env.example
.worktrees/は Git Worktree の作業ディレクトリであり、常に.gitignoreに含める。rules/worktree-layout.mdで定義された配置規約に対応する。
ユーザーに追加ルールが必要か確認する。
.gitignore が既に存在する場合:
✅ .gitignore を生成しました。
テンプレート: <templates>