In this tutorial we will learn to ignore files using the .gitignore file in Git repository.
This is the file that we add in our project folder and it tells Git to ignore files and directories that are mentioned.
Every file in the working directory of our project is seen by Git as one of the following.
An untracked file is one that has never been staged or committed.
A tracked file is one that has been staged or committed earlier.
An ignored file is one that is ignored by Git as it is explicitly told to do so.
As our project grows we will have multiple files and directories. In such a scenario it is not needed to save (commit) files and directories that are not of major importance.
For example, the hidden system files like .DS_Store or log files like .log and .lock and IDE config files like .idea/workspace.xml can be ignored as they are not the actual code of the project.
Similarly, build directories like dist/ or build/ which contains output files that can we regenerated every time we build our project can be easily ignored from the Git commit.
The .gitignore file contains some patterns that are matched with files in our project folder (working directory) and Git then decides whether or not to exclude (ignore) the files from commit based on pattern match.
Open the project folder in terminal and run touch .gitignore command and it will create the file. Or you can create a file from your IDE and save it as .gitignore file.
Following are some of the patterns that you can use in the .gitignore file.
Copyright © 2014 - 2018 DYclassroom. All rights reserved.
rendered in 0.0763 sec