Last Updated:

Use .gitignore in an existing or existing project



There are situations when you work on a project, upload new commits to Git, and notice that everything with all your files also flies away and system files: data of your IDE, temporary application configurations, cache data, and so on. These files do not need to be controlled using Git, as they will always be different, will constantly change and your manipulation of their personas is essentially pointless. For this reason, .gitignore appeared.

A .gitignore is a file that stores records of directories and files that do not need to be tracked by SCR.

Creating a .gitignore

In order to work adequately with .gitignore, you must have Git installed and configured, and you must have an existing project. Open the console, navigate to the directory where the desired project is located. Type the following command


A .gitignore file (perhaps hidden) will appear in the directory.


Use .gitignore

At the moment, changes are tracked in the images directory and other files. Please ask Git not to track the images directory. Open the .gitignore, for example, via Notepad. Type the following in the file

The slash symbol at the end of the driectorial name is necessary in order to also ignore the entire contents of the directory. Don't forget to save the file. Now let's see in which places of our project there were changes using the command


Changes to the images directory and all attachments in it are no longer tracked.

Use .gitignore in an existing or existing project

Since the project is existing and our "unnecessary" files have already been committed, it is necessary to reset the cache from these files and directories otherwise the changes will still be monitored.

Open the console and run the following command to remove the directory cache

To delete the file cache, use the following command

The next time you commit, the files and directories for which the cache was cleared and located in .gitignore will be identified as deleted, but you will have them on your computer and will no longer be monitored.