.gitignore Creation and Management
Templates and Initial Scaffolding
The GitHub CLI (gh) has a gh repo gitignore command that can be used to fetch templates from GitHub's collection. gh repo gitignore list will output the list of templates in GitHub's collection to stdout. When you have the name of the one you want, use gh repo gitignore view [TEMPLATE] to have the content output to stdout, which you can redirect to a .gitignore file or wherever you need it. This is the easiest way to spike out the boilerplate for a given project type.
The rest of the Skill covers manually adding entries in gitignore syntax for the specific project you're working in.
/path vs path/ vs path
| Pattern | Meaning |
| --------- | --------- |
| path/ | Matches a directory named path (and its contents) |
| path | Matches both files AND directories named path |
| /path | Matches path relative to the .gitignore file's location (anchored path) |
Examples:
build/ignores thebuilddirectory and all its contentsbuildignores any file or directory namedbuildanywhere in the tree/buildignores only thebuilddirectory in the same folder as the .gitignore
Wildcard/Globbing Patterns
Git uses fnmatch-style patterns:
| Pattern | Matches |
| --------- | --------- |
| * | Any sequence of characters (except /) |
| ** | Any sequence of directories (including zero) |
| ? | Any single character |
| [abc] | Any one character in the set |
| [a-z] | Any one character in the range |
Examples:
*.logignores all.logfiles**/node_modulesignoresnode_modulesat any depthsrc/*.jsignores.jsfiles directly insrc/file?.txtmatchesfile1.txt,file2.txt, etc.a/**/bmatchesa/b,a/x/b,a/x/y/b/**/bmatchesbanywhere in the tree
Negation and Special Patterns
| Pattern | Purpose |
| --------- | --------- |
| !pattern | Negates — re-includes previously ignored files |
| # | Comment line |
| \ | Escape character for literal patterns |
Example:
# Ignore all .log files
*.log
# But not this specific one
!important.log