github/gitignore · C++.gitignore
C++ .gitignore Template Explained
Why C++.gitignore ignores objects, libraries and executables, CMake build trees, compile_commands.json and the vcpkg install folder, and the pitfall of the Makefile rule.
C++.gitignore adds CMake build trees, CTest results and the vcpkg manifest-mode install folder to compilation-output rules similar to the C template. Because the Fortran template in the template repository points directly to this file, it also contains rules for Fortran module files (.mod, .smod).
The line to be most careful with is Makefile. The rule is meant to block Makefiles generated by CMake, but in a project that builds with a hand-written Makefile, that file is ignored too.
Rules explained
| Pattern | What it ignores and why |
|---|---|
*.o*.obj*.slo*.lo*.d*.gch*.pch | Objects and header cachesPer-translation-unit compilation results, dependency files and precompiled headers. All are rebuilt from source. |
*.so*.dylib*.dll*.so.**.a*.lib*.lai*.la*.exe*.out*.app | Libraries and executablesLink output. It is built differently for each platform, so distribute it through releases rather than the repository. |
build/Build/build-*/CMakeFiles/CMakeCache.txtcmake_install.cmakeinstall_manifest.txt | CMake build treeCaches and generated files that CMake creates during the configure step. CMakeCache.txt stores your machine's compiler paths and is useless to anyone else. |
Makefile | Generated MakefilesBlocks Makefiles that CMake's Unix Makefiles generator creates inside the source tree. Because there is no slash, Makefile is ignored at any depth. |
compile_commands.jsonvcpkg_installed/Testing/.cache/ | Tool outputThe compilation database read by clangd and others, packages installed by vcpkg, CTest results and the clangd index cache. All of them depend on the local environment. |
*.pdb*.ilk*.dwo*.tmp*.log*.bak*.swp | Debug info and temporary filesDebug symbols, incremental link files, and editor temporary and backup files. |
*.mod*.smod | Fortran modulesModule interface files produced by Fortran compilers. They have no effect on pure C++ projects. |
Practical notes
- If you have a hand-written
Makefile, add!/Makefileor an exception rule for that path. Putting aMakefilepath into the pattern tester shows the problem right away. - Some teams keep
compile_commands.jsonas a symlink at the root and share it. In that case, remove this line. vcpkg.json(the manifest) andvcpkg-configuration.jsonare not ignored, so commit them.- If you use CLion, the
cmake-build-*/rule in the JetBrains template blocks the IDE build folders.
Original template
C++.gitignore
# Prerequisites*.d# Compiled Object files*.slo*.lo*.o*.obj# Precompiled Headers*.gch*.pch# Linker files*.ilk# Debugger Files*.pdb# Compiled Dynamic libraries*.so*.dylib*.dll*.so.*# Fortran module files*.mod*.smod# Compiled Static libraries*.lai*.la*.a*.lib# Executables*.exe*.out*.app# Build directoriesbuild/Build/build-*/# CMake generated filesCMakeFiles/CMakeCache.txtcmake_install.cmakeMakefileinstall_manifest.txtcompile_commands.json# Temporary files*.tmp*.log*.bak*.swp# vcpkgvcpkg_installed/# debug information files*.dwo# test output & cacheTesting/.cache/
Templates from github/gitignore/C++.gitignore @356fd7b (2026-09-11) · CC0-1.0