.gitignore vs .gitattributes vs .distignore: Understanding Git Ignore Files the Right Way
.gitignore vs .gitattributes vs .distignore
If you work with Git long enough, you’ll eventually encounter three files that look deceptively similar: .gitignore, .gitattributes, and .distignore. They often live side by side in a repository, yet each one serves a completely different purpose.
This article breaks down what each file does, how they differ, and when you should use them—without myths or guesswork.
What is .gitignore?
.gitignore tells Git which files or directories should not be tracked. These files never enter version control unless they were already committed before being ignored.
Common examples include dependency folders, environment files, and build artifacts that are generated locally.
node_modules/
vendor/
.env
.DS_Store
Once ignored, Git simply pretends these files do not exist. They are not committed, not pushed, and not shared with teammates.
What is .gitattributes?
.gitattributes controls how Git treats files, not whether they are tracked.
It influences behavior such as line endings, diff handling, merge strategies, and export rules.
This file is especially important in cross-platform teams and automated build pipelines.
*.php text eol=lf
*.png binary
/tests export-ignore
/.github export-ignore
One powerful but often overlooked feature is export-ignore. When Git creates an archive (for example using git archive), any file marked with export-ignore is excluded from the generated package.
The key point: files remain fully tracked in Git—they are just treated differently under certain operations.
What is .distignore?
.distignore is not a Git feature. Git itself does not read or care about this file at all.
Instead, .distignore is used by external tools when building a distributable package. It is most commonly seen in WordPress plugin and theme development.
node_modules
src
tests
.git
.github
*.map
During deployment—such as pushing a plugin to WordPress.org—these files are excluded from the final build, even though they exist in the Git repository.
In short, .distignore controls what gets shipped to users, not what Git tracks.
Key Differences at a Glance
Although they look similar, these files operate at different layers:
- .gitignore decides what Git tracks
- .gitattributes decides how Git treats tracked files
- .distignore decides what gets included in a distribution
They solve different problems and are often used together in professional projects.
Real-World Usage (Especially for WordPress)
In WordPress plugin development, it’s common—and recommended—to use all three files:
.gitignoreto exclude local and generated files.gitattributesto control line endings and GitHub archives.distignoreto keep deployment packages clean and lightweight
This separation keeps your repository complete while ensuring users receive only what they need.
Final Thoughts
Version control and distribution are not the same thing.
Git is concerned with history and collaboration, while deployment is concerned with efficiency and safety.
Understanding the difference between .gitignore, .gitattributes, and .distignore helps you design cleaner repositories, smoother CI/CD pipelines, and more professional releases.
Need to build a Website or Application?
Since 2011, Codeboxr has been transforming client visions into powerful, user-friendly web experiences. We specialize in building bespoke web applications that drive growth and engagement.
Our deep expertise in modern technologies like Laravel and Flutter allows us to create robust, scalable solutions from the ground up. As WordPress veterans,
we also excel at crafting high-performance websites and developing advanced custom plugins that extend functionality perfectly to your needs.
Let’s build the advanced web solution your business demands.