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)
- 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 access.log # The directory in any project directory will be ignored node_modules # The root directory of the current directory will be ignored /coverage # 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 /db/*.sqlite3 # ignore all .txt files in the doc/ directory # on all nesting levels doc/**/*.txt
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 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
- Add the .gitignore file to the project
- Ignore the INFO.md file and remove it from the repository
- Create an INFO.md file and make sure that
git statusdoes not display it
- Upload the changes to GitHub