Create .gitignores with templates from www.gitignore.io, your own aliases and templates
- Simple:
git ignore node
to print thenode
template. - Offline first: Automatically caches templates for offline support.
- Aliases, templates: Create aliases for commonly combined templates, or make your own custom ones.
- Magic: Automatically generate your
.gitignore
by matching common files against templates.
Tired of visiting gitignore.io to get templates for your
.gitignore
all the time? I was. So I automated it.
git ignore
allows you to easily and quickly get all the available templates from
gitignore.io, even while offline. You can also define
your own aliases for common combinations of templates, or create your own completely
custom ones for even more power.
Currently, the package is available a couple of places, including Homebrew, AUR and Nix.
- Cargo
cargo install git-ignore-generator
- Nix
nix-env -iA nixpkgs.gitAndTools.git-ignore
- Homebrew
brew install git-ignore
- Arch (replace
paru
with you favorite AUR tool) paru git-ignore-bin
paru git-ignore
You can also download the matching release from the release
tab, extracting the archive and
placing the binary in your $PATH
. Note that for Linux the
unknown-linux-musl.tar.gz
is preferred as it is statically linked and thus
should run on any Linux distribution.
NOTE: Similar to the nix-search
command, this program prints a message
to stderr
about using cached results. This does not interfere with piping
and is purely informational. You can also optionally use --write
to automatically
write the resulting ignores to $CWD/.gitignore
instead of piping.
To download and cache all available templates, use --update
. This can also be
used in combination with any of the other flags/arguments, or be run as a
standalone flag.
$ git ignore -u
Info: Update successful
By matching against project or language specific files and extensions you can have
your .gitignore
automatically generated for you. Do you have a package.json
and
Cargo.toml
in the current directory? --auto
will automatically add node
and rust
to the template output.
$ git ignore -a
### Created by https://www.gitignore.io
### Rust ###
[...]
# These are backup files generated by rustfmt
**/*.rs.bk
To list all the available templates:
$ git ignore --list
1c
1c-bitrix
a-frame
actionscript
ada
[...]
zukencr8000
The --list
option is also used to search for templates matching your input. The
matching is done by doing template.contains(phrase)
, so searching for intellij
will list all templates containing that phrase. You can also search for multiple
templates at once:
$ git ignore -l rust intellij
intellij
intellij+all
intellij+iml
rust
Once you've found your templates, you can print them by omitting -l|--list
. Note:
listing and searching for templates is inexact, but printing them requires exact matches.
$ git ignore rust intellij+all
### Created by https://www.gitignore.io
### Rust ###
[...]
# These are backup files generated by rustfmt
**/*.rs.bk
Aliases are a way to combine common combinations of templates, if you find
yourself always using node
and visualstudiocode
in your frontend projects
you can create an alias for it for ease of access. Aliases have higher priority
than templates from www.gitignore.io, so an alias named node
will be used
instead of the template. When listing all available templates, aliases are colored
yellow to allow you to distinguish them from regular templates.
$ git ignore alias list
Available aliases:
node => ["node", "nextjs", "visualstudiocode"]
rust => ["rust", "intellij+all"]
$ git ignore alias add node node nextjs visualstudiocode
Created alias node for ["node", "nextjs", "visualstudiocode"]
$ git ignore alias remove node
Removed alias node
Templates are custom templates created by you for things that do not have an
existing template defined. When listing and searching templates has the highest
priority (templates > alias > normal
). Templates are listed with a blue color
to distinguish them from aliases and normal templates.
The file name is the name of the file in $HOME/.config/git-ignore/templates
.
$ git ignore template list
Available templates:
docs => "docs.txt"
All templates are created in $HOME/.config/git-ignore/templates
. So the name
you give for the file is the filename that is used in this directory.
$ git ignore template add docs docs.txt
Created template docs at ~/.config/git-config/templates/docs.txt
$ git ignore template remove node
Removed template node
You can create the configuration file and directories by running git ignore init
. This
will create $HOME/.config/git-ignore/config.toml
and $HOME/.config/git-ignore/templates/
.
The config file is a simple TOML file:
[aliases]
node = [
'node',
'nextjs',
'visualstudiocode',
]
[templates]
docs = 'docs.txt'
If your method of installation didn't include shell completion, you can manually
source or save them with the git ignore completion <shell>
command.
Finally, help is always available with git ignore help
/git ignore -h
(or --help
if your installation
included man pages).
GPLv3+.