DEV Community


gig: a gitignore generator

shihanng profile image Shi Han ・4 min read

If you are using git in your project, you probably know what is .gitignore. Since I never seem to be able to memorized gitignore's pattern format correctly, when I needed to write a gitignore file for a specific project, I'll visit github/gitignore in my web browser, search for gitignore file, open the file, copy its content, then finally paste it into my editor...

Using github/gitignore

As we can imagine, if you need to create gitignore file for multiple programming languages the process becomes very tedious.

A while back I was introduced to which is a web service that allows us to create gitignore file easily for multiple languages. also provides API access and very nice documentation on how to run from your command line. It was a huge upgrade and I've been using this tool since then. I even submitted a PR to gitignore direnv:

Add direnv.gitignore #241

Based on

Pull Request

Thank you for contributing to @dvcs/gitignore and

New or update

Select the appropriate check box for this pull request. This helps when merging to ensure there are no conflicts with other templates or misunderstandings of how thee template list works.


  • [x] Template - New .gitignore template
  • [ ] Composition - Template made from smaller templates
  • [ ] Inheritance - Template similar to an existing template
  • [ ] Patch - Template extending functionality of existing template


  • [ ] Template - Update existing .gitignore template


direnv is a tool that can load and unload environment variables based on the current working directory. It is commonly advised to not to include its configuration file .envrc into a public repository therefore having this in the gitignore will be very handy. The values are based on this documentation:

Thank you.

However, after the PR got merged, I found out that the change is not reflected in (yet). My guess is that the maintainer needs to "redeploy" the site in order to include the latest collections.

$ curl

# Created by
# Edit at

#!! ERROR: direnv is undefined. Use list command to see defined gitignore types !!#

# End of's collections of gitignore templates are maintained in a separated repository: They are extensions of github/gitignore that include additional types known as .patch, .stack. When I bumped into the error above, I wondered if I can somehow generate the gitignore file using the repository directly without the web service. Which then lead me deep into the rabbit hole and created gig...

GitHub logo shihanng / gig

Generate .gitignore files from your terminal (mostly) offline!

gig -- .gitignore generator

GitHub GitHub release (latest by date) Go Report Card Coverage Status

gig is a command line tool to help you create useful .gitignore files for your project It is inspired by and make use of the large collection of useful .gitignore templates of the web service This also means that gig supports the are four file types that recognizes Content generated by gig should match the one generated by except the order of stacks in which does not seem to guarantee any.


Prior to this project, I used to have one of these command lines in my .zshrc. However, problems I have with this command line are that

Therefore this tool is created to solve…

Introducing gig

gig is a CLI port of and make use of the large collection of .gitignore templates of mentioned above. This also means that gig supports all four file types that recognizes and generates contents of gitignore like does.


If you are on macOS and are using Homebrew,

brew install shihanng/gig/gig

For other platforms, download the pre-built binaries from the release page then place the binary in the $PATH e.g. /usr/local/bin.


The most direct way of using gig is to use the gen subcommand with a list of template names as arguments, e.g.

gig gen go terraform > .gitignore

Example above generates gitignore templates for Go and Terraform then redirects those into .gitignore file. With additional -f flag, we can omit the redirect part of the command. gig command will cache the content of repository into $XDG_CACHE_HOME/gig during the first run. This means that the next execute should work offline.

When we want to look for available templates, we can use the list command. It's a pretty long list, so it works better with a pager:

gig list | less

There is also a search command which calls fzf -m internally on the list above and allows user to select (by pressing tab by default) the templates in fzf.

Finally there is the least useful autogen subcommand which was added just for fun.

gig autogen

It will look into the current directory and try to figure out what to gitignore. Internally it uses source{d}'s enry package for programming language detection (which itself is a port of GitHub's linguist). Unfortunately it does not always work as expected:

  • It is not able to detect framework, e.g. .js files will be detected as javascript but there is not JavaScript gitignore template available.
  • go.mod and go.sum files will be detected as text for the reason mentioned in this PR.

gig started as a fun project to see how far I can go to build a CLI tool with the remix of

Now it is has become a tool that I will use it when starting a new project.

Please give it a try and I would love hear your feedback (via issues/PRs in project repository or comments in this post). If you like it, give it a ⭐ so that other people will hear about it.

Thanks for reading ❤️

Discussion (5)

Editor guide
vlasales profile image
Vlastimil Pospichal

Global .gitignore

curl -s "" -o ~/.gitignore
git config --global core.excludesfile ~/.gitignore
vlasales profile image
Vlastimil Pospichal

This is not good for make .gitignore, but it is good for make .git/info/exclude.

shihanng profile image
Shi Han Author

I have to admit I did not know about about /info/exclude until just now. Thanks!

padakipavan profile image

This is great. Would love to use this as a vscode extension though. Keep up the good worth.

shihanng profile image
Shi Han Author

Thank you for the suggestion!