A file .gitignore
is used to tell Git which files and folders it should ignore. Often, these files are build artefacts, temporary files, or other types of files that don't belong in the repository. Git will disregard any directory or file that fits a pattern in the .gitignore
file.
Example:
# Ignore .DS_Store files
.DS_Store
# Ignore build artifacts
build/
# Ignore log files
*.log
Contrarily, a .gitkeep
file is utilised in Git to maintain a directory that would otherwise be empty. Git does not by default track empty folders, thus you must add a .gitkeep
file to that directory if you wish to keep it in your repository. The filename is more significant than the file's actual contents.
Example of .gitkeep
file
# This file is used to keep the directory empty in Git
In summary. The .gitignore
command is used to tell Git which files and folders to ignore. To maintain a Git directory that would otherwise be empty, use .gitkeep
. They are distinct from one another and have different functions.