The .gitignore file tells Git which files to ignore and not track in your repository. Every Git project should have a .gitignore file to keep unnecessary files out of the repo. For example, cache files should not be included in the main repository.
When working on projects, you often generate files that should not be committed to the version control system. These might include:
A .gitignore file tells Git which files or folders to ignore. This keeps your repository clean and ensures that only important files are tracked, improving efficiency.
Here are some useful patterns you might need in a .gitignore file:
"*" - (e.g. *.log This will ignore all files ending in .log anywhere in the repository.)
"**" - (e.g. **/lib/name.file This pattern will ignore name.file in any lib/ directory within the repository, no matter its depth.)
" /{{name}}/ " - (e.g. /build/ This will ignore the build/ directory only at the root level.)
For more details and advanced patterns, refer to the w3schools Gitignore tutorial.
bashnode_modules/.env*.log
Figure: Example of gitnore file
# Ignore environment variables for security.env# Ignore node_modules folder to avoid unnecessary files in the reponode_modules/
Figure: Example of gitignore file with comment