Skip to content
Pre-commit hook for running clang-format. Don't use this.
Branch: master
Clone or download
skident and andrewseidl Apply clang-format only on existing files (#6)
Fix a problem when file was renamed/moved
Latest commit 057e076 May 7, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information. Add link to integrated Visual Studio support (#3) Jun 7, 2018
clang-format.hook Apply clang-format only on existing files (#6) May 7, 2019


Don't use this. Instead, look into integrating clang-format into your editor.

This script will automatically run clang-format on all changed files in a commit when set as a pre-commit hook. Proceed with caution.


Do not use this on an existing codebase that isn't already in your desired style. Doing so will lead to a string a dirty commits where your code changes are intermixed with clang-format's formatting changes.

Furthermore, every developer will need to install this hook. If they don't, you will again end up with commits with a mixture of code and formatting changes.


First, verify that clang-format is installed. On Linux this should be included with the regular clang package. For MacOSX with Homebrew, clang-format is available via brew install clang-format.

Now install clang-format.hook from this repository into your repo's .git/hooks. If you don't already have a pre-commit hook, you can simply copy clang-format.hook to .git/hooks/pre-commit. For example:

cp githook-clang-format/clang-format.hook myrepo/.git/hooks/pre-commit


Once the pre-commit hook is installed, clang-format will be run on each file included in the commit when you run git commit.

By default, clang-format uses the LLVM style. To change this, either create a .clang-format file with your desired format in the top level of your repo, or set the config option in your repo. The .clang-format file method is preferred if you will be working with a team or will be doing any major customizations to the style.

You can generate the .clang-format file from your desired style (here, llvm) using:

clang-format -style=llvm -dump-config > .clang-format

To use the git config method, inside your repo do:

git config llvm

You can’t perform that action at this time.