Pimp My Git - Generate Content for .gitignore From the Scratch

When I start a new Git repository, I lose a lot of time to set up my .gitignore file and normally, I don't match everything on the first shoot. Fortunately, there exists some tools, that help to bootstrapping it. I'd like to show two of them. One is a website that can be used on the command line and the another is a plugin for the IDE IntelliJ IDEA.

Website gitignore.io

There is a website http://gitignore.io that lists the common ignore pattern for you specific programming language, tool, IDE etc. The usage is very simple: Fill the search with names of  tools, framework, programming language etc, which you want to use in your Git project, and the website generates the content for your .gitignore file. You can also run gitignore.io from your command line. Therefore, you need an active internet connection and an environment function. I'll demonstrate the integration of gitignore.io in zsh. For the integration in other shells or clients, please look into the documentation. Firstly, we have to create a function gi in our ~/.zshrc:

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

Now, we can use it on the command line.

 1$ gi java,maven # Preview of the content for .gitignore
 2
 3# Created by https://www.gitignore.io/api/java,maven
 4
 5### Java ###
 6# Compiled class file
 7*.class
 8
 9# Log file
10*.log
11
12# BlueJ files
13*.ctxt
14
15# Mobile Tools for Java (J2ME)
16.mtj.tmp/
17
18# Package Files #
19*.jar
20*.war
21*.ear
22*.zip
23*.tar.gz
24*.rar
25
26# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
27hs_err_pid*
28
29### Maven ###
30target/
31pom.xml.tag
32pom.xml.releaseBackup
33pom.xml.versionsBackup
34pom.xml.next
35release.properties
36dependency-reduced-pom.xml
37buildNumber.properties
38.mvn/timing.properties
39
40# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored)
41!/.mvn/wrapper/maven-wrapper.jar
42
43# End of https://www.gitignore.io/api/java,maven
44
45$ gi list # list currently available templates
461c-bitrix,a-frame,actionscript,ada,adobe
47advancedinstaller,agda,alteraquartusii,altium,android
48androidstudio,angular,anjuta,ansible,apachecordova
49apachehadoop,appbuilder,appceleratortitanium,appcode,appcode+all
50appcode+iml,appengine,aptanastudio,arcanist,archive
51archives,archlinuxpackages,aspnetcore,assembler,atmelstudio
52ats,audio,automationstudio,autotools,backup
53basercms,basic,batch,bazaar,bazel
54bitrix,bittorrent,blackbox,bluej,bower
55bricxcc,buck,c,c++,cake
56.... furthermore
57
58$ gi java,maven >> .gitignore # append the content in your project's .gitignore

IntelliJ IDEA Plugin - .ignore

There is a plugin for IntelliJ IDEA that helps creating .gitignore file with content for your selected tool, programming language etc. . At first you have to install the plugin .ignore (Go to File -> Settings -> Plugins and search for .ignore).

You can now create .gitignore file via the .ignore plugin. By the way, the plugin can also create ignore files for other tools like Docker or Mercurial. Then a file generator is opened and you can choose templates of tools, programming language etc that you will use in the Git project.A preview shows you the possible content. A click on Generate and you are ready. Do you have other tips and tricks to boost the initialization time of a Git project? Share them and write a comment below.

  1. gitignore.io
  2. Website of .ignore