The .gitignore file
What you do not version (compiled output, dependencies, secrets, editor files) and the syntax of .gitignore patterns: star, slash, double star, exclamation mark, and the case of an already tracked file.
- 20 cards
- 5 topics
- Free
The outline, topic by topic
Each topic is weighted the way the exam weighs it.
- Concepts
- Questions
- Sort and link
- Scenarios
- Understand
A few cards from the deck
The .gitignore file: what is it?
Show the answer
A text file, versioned with the project, that lists name patterns Git must leave untracked.
It only has an effect on files not yet tracked. Since it is versioned, the whole team shares the same rules.
.gitignore contains
*.class,/build/and!Main.class. Which statement is right?src/Main.classis not ignored,build/Main.classisbuild/Main.classis no longer ignored because of!Main.classsrc/Main.classis ignored, a!only works at the root- No
.classis ignored, the!cancels*.class
Show the answer
src/Main.classis not ignored,build/Main.classis!Main.classre-includes Main.class files outside build. But inbuild/, the whole folder is ignored, and Git does not look inside: nothing can be re-included there.Files the project can …, such as compiled binaries or downloaded dependencies, are not versioned.
Show the answer
Files the project can regenerate, such as compiled binaries or downloaded dependencies, are not versioned.
They weigh down the repository and create conflicts at every build. The source code and the dependency file are enough to reproduce them.
Pattern with a star (*): what is it?
Show the answer
Stands for any run of characters in a file name, never crossing a folder separator.
*.class ignores every .class file, but docs/*.pdf only reaches the files directly in docs, not those in subfolders.
You add
.envto .gitignore, butgit statusstill shows it as modified. What do you do so it is finally ignored, while keeping it on your disk?git rm .envthen a commitgit add .gitignorethen a commitgit restore .envso it becomes untracked againgit rm --cached .envthen a commit
Show the answer
git rm --cached .envthen a commitA .gitignore only concerns untracked files;
.envwas already tracked.--cachedremoves it from the index without deleting it, whereasgit rm .envwould delete it from the disk too, and committing the .gitignore changes nothing for a tracked file. Careful: its content stays in the history, so a secret has to be changed.