Gitignore Revisited
Tags: git, webdev
Published: 2019-10-29 22:08:46

---
title: Gitignore Revisited
published: true
description: 
tags: git, webdev
cover_image: https://thepracticaldev.s3.amazonaws.com/i/pufcsh9xztluxj9qc12w.jpg
---
I wanted to take the time to revisit the idea of a thorough `gitignore` file for your project repository. I few months ago I wrote an article about an extension to generate a `gitignore` file ([Gitignore in VSCODE](https://dev.to/eclecticcoding/gitignore-in-vscode-17da), but I am no longer using VS Code, and I have found a solution which everyone may find helpful.

## Setup 
Recently I have become sold on the [gitignore api](http://gitignore.io/). This API is relatively easy to setup and full featured for fine tuning your needs. 

**Setup**: It is pretty easy to start with, and you can read more in their docs. The documentation in this article will use ZSH as it is by shell of choice, but more configuration options are available on their [site](https://docs.gitignore.io/install/command-line).

Add the following to your `.zshrc` file:

```
echo "function gi() { curl -sLw "\n" https://www.gitignore.io/api/\$@ ;}" >> \
~/.zshrc && source ~/.zshrc
```

## Getting Output
So now what? Consider this sample command to get started for a java project on linux:
```
gi linux,java >> ./.gitignore
```
This will create a file that will generate `gitignore` which will exclude the normal temporary files for Linux and Java that you may not want in your repository. 

**Question**: *What is enough to include in this file? Are you pushing your project to a public repository?* If so, we may want a more complete `gitignore` file to keep the repository clean. 

The command `gi list` will show us all the possible configuration options. 
```
1c,1c-bitrix,a-frame,actionscript,ada
adobe,advancedinstaller,adventuregamestudio,agda,al
alteraquartusii,altium,android,androidstudio,angular
anjuta,ansible,apachecordova,apachehadoop,appbuilder
appceleratortitanium,appcode,appcode+all,appcode+iml,appengine
aptanastudio,arcanist,archive,archives,archlinuxpackages
aspnetcore,assembler,ate,atmelstudio,ats
audio,automationstudio,autotools,autotools+strict,awr
backup,ballerina,basercms,basic,batch
bazaar,bazel,bitrise,bitrix,bittorrent
blackbox,bloop,bluej,bookdown,bower
bricxcc,buck,c,c++,cake
cakephp,cakephp2,cakephp3,calabash,carthage
certificates,ceylon,cfwheels,chefcookbook,chocolatey
clean,clion,clion+all,clion+iml,clojure
cloud9,cmake,cocoapods,cocos2dx,cocoscreator
code,code-java,codeblocks,codecomposerstudio,codeigniter
codeio,codekit,codesniffer,coffeescript,commonlisp
composer,compressed,compressedarchive,compression,concrete5
coq,cordova,craftcms,crashlytics,crbasic
crossbar,crystal,csharp,cuda,cvs
d,dart,darteditor,data,database
datarecovery,dbeaver,defold,delphi,dframe
diff,diskimage,django,dm,docfx
docpress,dotenv,dotfilessh,dotnetcore,dotsettings
dreamweaver,dropbox,drupal,drupal7,drupal8
eagle,easybook,eclipse,eiffelstudio,elasticbeanstalk
elisp,elixir,elm,emacs,ember
ensime,episerver,erlang,espresso,executable
exercism,expressionengine,extjs,fancy,fastlane
finale,firebase,flashbuilder,flask,flex
flexbuilder,floobits,flutter,font,fontforge
forcedotcom,forgegradle,fortran,freepascal,fsharp
fuelphp,fusetools,games,gcov,genero4gl
geth,ggts,gis,git,gitbook
go,godot,goodsync,gpg,gradle
grails,greenfoot,grunt,gwt,haskell
helm,hexo,hol,homeassistant,hsp
hugo,hyperledgercomposer,iar,iar_ewarm,iarembeddedworkbench
idapro,idris,igorpro,images,infer
inforcms,inforcrm,intellij,intellij+all,intellij+iml
ionic3,jabref,java,java-web,jboss
jboss-4-2-3-ga,jboss-6-x,jboss4,jboss6,jdeveloper
jekyll,jenv,jetbrains,jetbrains+all,jetbrains+iml
jgiven,jigsaw,jmeter,joe,joomla
jspm,julia,jupyternotebooks,justcode,kate
kdevelop4,kdiff3,keil,kentico,kicad
kirby2,kobalt,kohana,komodoedit,konyvisualizer
kotlin,labview,labviewnxg,lamp,laravel
latex,lazarus,leiningen,lemonstand,less
liberosoc,librarian-chef,libreoffice,lilypond,linux
lithium,logtalk,lsspice,ltspice,lua
lyx,m2e,macos,magento,magento1
magento2,magic-xpa,matlab,maven,mavensmate
mdbook,mean,mercurial,mercury,metals
metaprogrammingsystem,meteor,meteorjs,microsoftoffice,mikroc
moban,modelsim,modx,momentics,monodevelop
mplabx,mule,nanoc,nativescript,ncrunch
nesc,netbeans,nette,nikola,nim
ninja,node,nodechakratimetraveldebug,notepadpp,nuxt
nuxtjs,nwjs,objective-c,ocaml,octave
octobercms,opa,opencart,opencv,openfoam
openframeworks,openframeworks+visualstudio,oracleforms,orcad,osx
otto,oxideshop,oxygenxmleditor,packer,particle
patch,pawn,perl,perl6,ph7cms
phalcon,phoenix,phpcodesniffer,phpstorm,phpstorm+all
phpstorm+iml,pico8,pimcore,pimcore4,pimcore5
pinegrow,platformio,playframework,plone,polymer
powershell,premake-gmake,prepros,prestashop,processing
progressabl,psoccreator,puppet,puppet-librarian,purebasic
purescript,putty,pvs,pycharm,pycharm+all
pycharm+iml,pydev,python,qml,qooxdoo
qt,qtcreator,r,racket,rails
react,reactnative,reasonml,red,redcar
redis,rhodesrhomobile,rider,root,ros
ruby,rubymine,rubymine+all,rubymine+iml,rust
salesforce,salesforcedx,sas,sass,sbt
scala,scheme,scons,scrivener,sdcc
seamgen,senchatouch,serverless,shopware,silverstripe
sketchup,slickedit,smalltalk,snap,snapcraft
solidity,soliditytruffle,sonar,sonarqube,sourcepawn
spark,splunk,spreadsheet,ssh,standardml
stata,stdlib,stella,stellar,stylus
sublimetext,sugarcrm,svn,swift,swiftpackagemanager
swiftpm,symfony,symphonycms,synology,synopsysvcs
tags,tarmainstallmate,terraform,terragrunt,test
testcomplete,testinfra,tex,text,textmate
textpattern,theos-tweak,thinkphp,tortoisegit,tower
turbogears2,twincat,typings,typo3,typo3-composer
umbraco,unity,unrealengine,vaadin,vagrant
valgrind,vapor,venv,vertx,video
vim,virtualenv,virtuoso,visualstudio,visualstudiocode
vivado,vlab,vue,vuejs,vvvv
waf,wakanda,web,webmethods,webstorm
webstorm+all,webstorm+iml,werckercli,windows,wintersmith
wordpress,wyam,xamarinstudio,xcode,xcodeinjection
xilinx,xilinxise,xilinxvivado,xill,xojo
xtext,y86,yeoman,yii,yii2
zendframework,zephir,zig,zsh,zukencr8000
```

So, let's consider this extensive list and build a command for JavaScript project in a public repository. 
- OS Files: linux,macos,windows
- Editor files: jetbrains+all,visualstudiocode,sublimetext
- Project languages: node,react,reactnative,vue,vuejs

**EDIT**(thank you [James](https://dev.to/nylen): Now, a word about local OS AND EDITOR files. According to [Git Manual](https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration), these files are best placed in a local `.gitignore_global` file in the root of your home directory own your computer. 
So on my Linux computer, considering the editors I use from time to time: 
```
gi linux,visualstudiocode,jetbrains+all,sublimetext,vim >> ~/.gitignore_global
``` 
After creating the global file, you need to configure `git`:
```
git config --global core.excludesfile ~/.gitignore_global
```
Now, all repositories on your computer will ignore these files.
 

This final command will create a `gitignore` file in your current folder:
```
gi node,react,vue,vuejs >> ./.gitignore

```

Who wants to remember all of that? Create an alias in `zshrc`:
```
alias ginode="gi node,react,vue,vuejs >> ./.gitignore"
```
Now all you have to do is issue `ginode` in your project directory. 

I hope you have found this helpful and feel free to start a conversation. 



Cover Photo by [Markus Spiske](https://unsplash.com/@markusspiske?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText) on [Unsplash](https://unsplash.com/s/photos/code?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)