C .gitignore template
The C template ignores everything the compiler and linker emit, from individual object files up to shared libraries and platform specific debug symbol bundles.
At a glance
- Category
- Language
- Patterns in this template
- 23 rules
- Directories ignored
- 1 of the 23 rules end in a slash, so they match directories only
- Also needs an OS template
- Yes, and the choice matters here: the dSYM rule is the only macOS aware line in the template.
- Typical companions
- Make or CMake conventions of your own, plus an editor and an OS template.
In detail
The compilation pipeline leaves a trail at every stage and this template follows it. *.o and *.obj are the object files produced from each translation unit before linking, one per source file, and they are the single largest source of churn in a C repository that forgets to ignore them. *.gch and *.pch are precompiled headers, an optimisation that is entirely local to one build configuration.
The library rules cover both halves of the linking story. *.a and *.lib are static archives, *.so, *.so.* and *.dylib are shared objects on Unix, macOS and their variants, and *.dll is the Windows equivalent. *.la and *.lo come from libtool. All of these are outputs, but they are also exactly the file types you might legitimately vendor as a prebuilt third party dependency, so check before assuming the rule is harmless.
Executables are covered by *.exe, *.out and *.app. On Linux and macOS a compiled binary often has no extension at all, so the same gap that affects other compiled languages applies here: a binary named after your project will not be matched unless you add a rule or build into an ignored directory.
The debug symbol rules are platform specific. *.pdb and *.idb are the Windows symbol database and its intermediate form. *.dSYM/ is the macOS symbol bundle, which is a directory rather than a file and can easily be larger than the binary it describes. *.elf and *.ilk cover embedded output and incremental linker state.
Two rules deserve a second look. *.map is a linker map file listing symbol addresses, but the same extension is used by source maps in a repository that also contains web assets. *.su is a stack usage file from the compiler, harmless but obscure enough that people delete the line without knowing what it was.
Examples
*.o
*.obj
*.elf
*.ilk
*.map
*.exp
*.gch
*.pch
*.lib
*.a
*.la
*.lo
*.dll
*.so
*.so.*
*.dylib
*.exe
*.out
*.app
*.dSYM/
*.su
*.idb
*.pdb23 lines exactly as the tool writes them, before any common additions you tick.
Things that catch people out
- *.a and *.lib will silently ignore a prebuilt static library you meant to vendor. If your build depends on a checked in third party archive, add a negation for that exact path.
- *.map collides with source map files in any repository that mixes C with web assets. Anchoring the rule to your build output directory avoids the collision.
- An extensionless binary produced by a bare cc invocation matches none of these rules. Prefer a build directory that is ignored wholesale.
Try it: .gitignore Generator
Pick one or more templates, tick the common additions you want, and copy or download the combined .gitignore.
.gitignore Generator
LOCAL · Browser-OnlyGenerate comprehensive .gitignore files by combining templates for languages, frameworks, IDEs, and operating systems
Language
Framework
IDE
OS
Build Tool
Infrastructure
Common Additions
Preview
Select templates or common additions to generate a .gitignore file.
Related .gitignore templates
All .gitignore templates →C++ .gitignore template
The C++ template adds CMake output to the usual compiler artefacts, and its Makefile rule will ignore a hand written Makefile. Here is what each line covers.
Rust .gitignore template
The Rust template ignores the target directory and leaves Cargo.lock tracked. Whether that is right depends on whether you ship a binary or a library.
Go .gitignore template
The Go template ignores platform binaries by extension, which misses the extensionless binary go build produces on Linux and macOS. Here is what to add.
C# .gitignore template
Why the C# template writes [Bb]in instead of bin, what the NuGet and Visual Studio rules cover, and which per developer files it keeps out of the repository.
Ruby .gitignore template
The Ruby template anchors most rules to the repository root with a leading slash, and ignores Gemfile.lock, which is right for a gem and wrong for an app.
PHP .gitignore template
The PHP template ignores the vendor directory and the .env file, and also ignores composer.lock, which most application projects should commit instead.
Tools for this
- .gitignore Generator Generate .gitignore files for any project - 50+ templates for languages, frameworks, IDEs, and OS