How to Create GitIgnore File The Easy Ways

Haydar Ali Ismail
3 min readFeb 10, 2017

Last time, we have talked about how to specify files or folders that we need to ignore. If you haven’t read about it, you can check it on the link below.

However, creating it manually is such a problem. Fortunately, we have a way to generate GitIgnore file automatically without creating it by our self. There are several ways of creating GitIgnore automatically, and here are how.

Methods

1. Using IDE

Some IDE generates the GitIgnore file automatically when creating a new project. As far as I know, all of IntelliJ IDE (Android Studio, RubyMine, PyCharm, etc) already automatically generate the GitIgnore file. However, I do actually have some problem with the generated GitIgnore file in the past. The GitIgnore in Android Studio at that time (it’s in 2015, not sure if it’s already fixed or not) still allow files generated by the Android Studio IDE that isn’t actually needed to share the codes across PC getting tracked. Some of those files are from the .idea folder and there are several .iml files. In return, those files are tracked, and when copied to other PC, there are a lot of errors because of the difference in the environment setting between those PCs. After that experience, I didn’t really use this method anymore. The important thing to note is that not all IDE do this, so if you want to do it by this way you need to make sure that the IDE really generate the GitIgnore file with the right rule. This is by far the easiest one because the IDE should automatically do it, but I suggest you to still check the GitIgnore file and fix if they still not ignore some files or folders that you don’t need to track.

2. Using Git Repository Hosting

Most Git Repository Hosting such as GitHub or Bitbucket already implemented this feature. This feature is available when we are going to create a new repository. In Github, you might notice that there is an option to generate the GitIgnore file. The image is attached below.

Adding .gitignore file is as easy as clicking!

We can choose from various frameworks and programming languages on the drop down menu in GitHub website. As far as I know, to include the GitIgnore file from the Repository Hosting website, we have to create a new repository. So, it seems we can’t doing it by this method if we already have a current project locally. If it is actually possible, please do tell me in the response below.

3. Using gitignore.io Website

This one is my favorites. There is a website out there called gitignore.io. Similar to GitHub, we can choose from the provided framework and programming languages. The plus point of using this website is that we can choose multiple frameworks and multiple programming languages and merge it into one GitIgnore file. This is typically useful if you’re going to make a project with multiple platforms but you only want to store it in one Git repository. Actually, I think the GitIgnore file generated from GitHub (I don’t know about the others) is actually generated based on this website. But, only this website allows combining multiple framework and languages.

We can combine multiple framework, IDE, and programming languages

Wrap Up

Today, we have talked about creating GitIgnore file automatically rather than manually create it. Hopefully, this story will help you to understand better of how to prepare your Git project by adding a GitIgnore file.

--

--