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.

Open in generator Open with C, JetBrains, VisualStudioCode, VisualStudio

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

PatternWhat it ignores and why
*.o*.obj*.slo*.lo*.d*.gch*.pchObjects 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*.appLibraries 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.txtCMake 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.
MakefileGenerated 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*.swpDebug info and temporary filesDebug symbols, incremental link files, and editor temporary and backup files.
*.mod*.smodFortran modulesModule interface files produced by Fortran compilers. They have no effect on pure C++ projects.

Practical notes

Original template

C++.gitignore39 rules
# 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

Often used together

More template explanations