What are the commonly used methods to auto-generate the .gitignore file?


The .gitignore file is a text file that tells Git which files or folders should be ignored while committing changes to the repository. This file lists the project files that we do not want Git to track for us.

Following are the two commonly used methods to auto−generate the .gitignore file −

Using the Github Site

The GitHub Site provides a collection of useful .gitignore templates for different technologies. The below screenshot shows a list of .gitignore templates provided by the site.

Let us say you are working on a Java project and would want to add a .gitignore file. All you have to do is −

Step 1 − Create an empty text file .gitignore and place it at the root of the project folder

Step 2 − Copy the contents of the .gitignore template for Java (that is shown below) into the file you have created.

Step 3 − Stage and commit the .gitignore file

Using Gitignore.io

Another recommended approach for creating .gitignore files is using the Gitignore.io tool.

As shown in the above screenshot, we can create a .gitignore file based an Operating System, IDE or Programming Language. Perform the following steps:

  • Enter the desired OS, IDE or Programming language and click on Create button. The tool will auto−generate the .gitignore file and render it in the browser. The following screenshot shows a .gitignore file created by the tool for a Golang project.

  • Create an empty text file in the project repository by the name .gitignore and copy the content generated by the tool

  • Index and commit the .gitignore file.

Updated on: 20-Feb-2021

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements