Generate .gitignore files with Bash function
06 Sep 2014No more copy/pasting lines from old
.gitignore
files
Every Git repo needs a .gitignore
file, these often vary from project to project and creating them can be a tedious process.
This process used to, at least for me, involve copy/pasting from previous projects only to end up with a new project-specific Frankenstein-like file. Around a year ago I stumbled upon the site gitignore.io which makes it super simple to generate .gitignore
files without resorting to copy/pasting from old projects.
The only problem was that when I start new projects Iāll usually be in my Terminal or editor of choice, and I donāt want to switch contexts by going to a website to generate the file.
gitignore.io offers an official and very simple command line utility, thatās documented here - but it doesnāt quite do as much as I wanted it to.
Luckily @soerenr sent me a link to this great little Gist by kqr.
I havenāt written much Bash besides a couple of small scripts here and there, but I thought I could add one little feature to the original gist by kqr. The ability to append existing .gitignore
files.
Here is the full slightly edited function:1
The code should be fairly self explanatory and straight-forward to understand. To use the function in your Bash shell: