What is the purpose of .gitignore vs. .gitattributes?
Last updated
Both are config files but solve different problems: .gitignore tells Git which untracked files to not track, while .gitattributes tells Git how to handle files it does track (line endings, diff, merge, filters).
.gitignore:Lists patterns for files/dirs Git should ignore: build output,
node_modules/, logs, secrets.Only affects untracked files: already-tracked files are not ignored.
.gitattributes:Assigns behavior per path:
text=autofor line-ending normalization,binaryto disable diff/merge.Configures diff/merge drivers,
export-ignorefor archives, and filters likeGit LFS.
In short:
.gitignorecontrols presence in the repo;.gitattributescontrols treatment within the repo.
- https://medium.com/@pengcheng1222/mastering-git-part-1-understanding-the-roles-of-gitignore-gitattributes-and-gitkeep-0c1558fcdd1a
- https://dev.to/charan_gutti_cf60c6185074/mastering-gitignore-keep-your-git-repo-clean-and-professional-c3h
- https://codeboxr.com/gitignore-vs-gitattributes-vs-distignore/
- https://www.geeksforgeeks.org/git/gitattributes-vs-gitignore-in-git/
- https://git-scm.com/docs/gitattributes
- https://git-scm.com/book/ms/v2/Customizing-Git-Git-Attributes