.gitignore for C++

C++ compiled objects, precompiled headers, and build artifacts.

Quick presets

Selected (1)
C++
Your selections never leave your browser. Generation happens entirely client-side.
Raw

20 patterns · 251 B

# Generated by DevZone Tools — https://devzone.tools/tools/gitignore-generator
# Templates: C++
# 2026-04-20

# ---- C++ ----
# C++
*.d
*.slo
*.lo
*.o
*.obj
*.gch
*.pch
*.so
*.dylib
*.dll
*.lai
*.la
*.a
*.lib
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

What this template ignores

Ignores compiled .o/.obj files, precompiled headers (.gch, .pch), static and shared libraries, and compiled executables.

Common additions

  • +.cache/ — clangd LSP cache
  • +compile_commands.json — can be committed for editor support

Commonly paired with

Frequently asked questions

Do I need to commit .gitignore?
Yes — .gitignore should be committed to the repository so all collaborators benefit from the same ignore rules.
How do I add custom patterns?
Open your .gitignore file and add the pattern on a new line. Use # for comments, * for wildcards, / to match directories, and ! to un-ignore a previously ignored path.
How do I ignore a file that is already tracked?
Adding a file to .gitignore does not remove it from tracking if it was previously committed. Run: git rm --cached <file> to stop tracking it without deleting the file locally.
Should I commit compile_commands.json?
compile_commands.json (generated by CMake or Bear) helps editors like clangd provide accurate completion. You can commit it for shared editor configs, but it is build-system-specific so many teams ignore it.

Looking for something else? Browse all templates →