CLI tool to easily add and remove Git .gitignore
templates obtained from
https://github.com/github/gitignore. Instead of manually writing or copying what
files to ignore for your project, you can use them instead!
For instance, for projects written in Python, you can safely ignore the
directory __pycache__/
and many other files, included in
Python.gitignore
.
Calling the following will write the contents of that file in ./.gitignore
:
gitignore add python
This was tested using Python 3.7 (but probably compatible with previous
versions). It also uses https://github.com/simonwhitaker/gibo as a back end.
Make sure to have the required Python version and the gibo
executable on the
PATH (like in ~/bin/
).
You can then also put this project's executable on the PATH, and source the Bash
completion file (doing something like putting
. gitignore-modifier/bash-completion/gitignore
in ~/.bashrc
).
add [<name>...]
: create.gitignore
if needed, and add templatesclear
: remove all templateshelp
: display the usage textlist [-a]
: list templates in.gitignore
;-a
to include other linesremove <name>...
: remove templatesupdate [<name>...]
: update all or specified templates to latest version
Within the .gitignore
, each template is preceded by the line
##gitignore-start:<name>
and followed by the line ##gitignore-end:<name>
.
This allows the script to parse .gitignore
file and know which templates are
already within.
To get the content of templates, the script calls gibo and parses its output appropriately.
The lines of .gitignore
are kept in place as much as possible to avoid
unncessary diff lines when changing it.
Adding the name of a gitignore template within another template will make the
parser automatically fetch that template. For example, the template for Fortran
consists of a single line "C++.gitignore
". This tells the parser to fetch the
C++ gitignore. There can be multiple links, and they can be put on anywhere
within the file, but they must be the only thing in a line.
The templates might include files you don't want to ignore. If so, you'll have
to manually edit the .gitignore
file or force Git to not ignore them.