Register to get access to free programming courses with interactive exercises

Ignoring files (Gitignore) Git fundamentals

While working on any project, in the directory will occur files that are not part of the source code. All these files can be divided into several groups:


  • Service files added by the operating system (.DS_Store on MacOS)
  • Configuration and temporary editor files (e.g., .idea, .vscode)

Temporary files

  • Logs. These contain useful information for debugging, which is collected during the launch and operation of the application
  • Caches. These are files that are needed to speed up various processes


  • Project build results. For example, after compiling or building the frontend
  • Dependencies installed during development (e.g., node_modules, vendor)
  • Test results (e.g., information on code covered by tests)

None of this should normally go into the repository. As a rule, these files are of no use from the point of view of the source code. They're created either automatically (caches, logs) or on request (e.g., downloading dependencies or building a project). The main problem with these files is that they are constantly changing at typically very large sizes. If you add them to the repository, almost every commit will have a bunch of changes to these files in addition to changes to the source code. Reading the history of such commits is extremely difficult as a result.

Git gives you the flexibility to ignore certain files and directories. This is done with the file .gitignore, which must be created in the project root. Files and directories to ignore are added to this file. For example:

# In this file you can leave comments
# File name .gitignore
# You need to create the file yourself

# Each line is a pattern that will be ignored

# A file in any project directory will be ignored

# The directory in any project directory will be ignored

# The root directory of the current directory will be ignored

# All files with the sqlite3 extension in the db directory will be ignored,
# but the same files inside any subdirectory in the db will not be ignored
# for example /db/something/lala.sqlite3

# ignore all .txt files in the doc/ directory
# on all nesting levels

Git supports file ignoring but does not set it up itself. To ignore files and directories, the programmer must create a .gitignore file in the root of the project, like this one and add it to the repository.

touch .gitignore
# add ignore rules to the file following the example above
git add .gitignore
git commit ...

As soon as git "sees" the .gitignore file, ignore will work automatically. Any new files that are ignored will not appear in the git status command output.

On occasion, a programmer may have already accidentally added a file to the repository that should be ignored. In this situation, it is not enough to simply update the ignore rules. You'll also have to remove the file or directory from git using git rm and commit.

Do it yourself

  1. Add the .gitignore file to the project
  2. Ignore the file and remove it from the repository
  3. Create an file and make sure that git status does not display it
  4. Upload the changes to GitHub

Recommended materials

  1. A collection of useful gitignore for all situations

Hexlet Experts

Are there any more questions? Ask them in the Discussion section.

The Hexlet support team or other students will answer you.

About Hexlet learning process

Sign up

Programming courses for beginners and experienced developers. Start training for free

  • 130 courses, 2000+ hours of theory
  • 1000 practical tasks in a browser
  • 360 000 students
By sending this form, you agree to our Personal Policy and Service Conditions

Our graduates work in companies:

<span class="translation_missing" title="translation missing:">Bookmate</span>
<span class="translation_missing" title="translation missing:">Healthsamurai</span>
<span class="translation_missing" title="translation missing:">Dualboot</span>
<span class="translation_missing" title="translation missing:">Abbyy</span>
Suggested learning programs
Development of front-end components for web applications
10 months
from scratch
Start at any time
Layout with the latest CSS standards
5 months
from scratch
under development
Start at any time
Developing web applications with Django
10 months
from scratch
under development
Start at any time

Use Hexlet to the fullest extent!

  • Ask questions about the lesson
  • Test your knowledge in quizzes
  • Practice in your browser
  • Track your progress

Sign up or sign in

By sending this form, you agree to our Personal Policy and Service Conditions
Toto Image

Ask questions if you want to discuss a theory or an exercise. Hexlet Support Team and experienced community members can help find answers and solve a problem.