Clang-format git hook


Clang-format git hook

Clang-format integration in Git is done from client side through git pre-commit hook that runs an clang-format style check only for .c, .cxx, .h, .cpp files that you modified during commit.


  • create a patch of the proposed style changes;
  • git hook can provide a preview of possible modifications;
  • user can select if to apply patch or not (through bash dialog window).

Important to know

We have our own .clang-format file in root of Git repository - there are some specific changes concerning length of line (120 symbols).

.Clang-format file should be automatically used by clang-format git hook.

How to install and use hook?

  • Download or install clang-format, after please add  binary location for clang-format in the $PATH
  • Clone or pull master of repository VecGeom or GeantV
  • Run: sh hooks/
  • …Write beautifull code…
  • Add files git add 'modified files'
  • Commit files git commit -m “[VECGEOM/GEANT-xx] My message”

    (please don't forget to add JIRA numbers of issues that you are fixing, you will have JIRA git hook after clang-format hook)
  • Check proposed version of modification of file by clang-format
  • Select please correct decision:
    • "Do you want to install patch (Yes - commit with patch, No - commit without patch, Cancel - stop committing)? [Y/N/C]"
    • IMPORTANT: Answer is case-sensitive: please write your choice with capital letters (Y, N , C)


  • Please don't forget that after clang-format hook, you also have JIRA hook that ask you to start your commit with [GEANT-xxx] and [VECGEOM-xxx]