CommitFence
Esc
↑ ↓ to moveEnter to open

Quick start

From a download to a first refused push, in six steps. Every command and every line of output below is from a real run of the command line, in a small scratch repository.

  1. 1

    Download and unzip

    Pick the file for your system. CommitFence is the app with the command line beside it; commitfence-cli is the command line alone. Both are self-contained: no .NET install is needed to run them. Unzip it where you want it to stay. SHA256SUMS.txt in the same release lists the checksum of every file.

    All releases on GitHub

    Version 1.0.0.0 · 23 November 2026 · What's new

    A review builds the changed projects, so the machine that pushes needs the .NET SDK.

  2. 2

    Install the command line

    Run commitfence install from the unzipped folder. It records where the program is in a git setting, commitfence.path, and puts its folder on your PATH. To see what it would do first, add --print.

    Terminal
    $ commitfence install --printWould set the git setting commitfence.path to Q:/CommitFence/commitfence.exe.Would add Q:\CommitFence to your PATH, for programs started after that.exit code 0

    The folder here is wherever the download was unzipped: Q:\CommitFence in this run.

  3. 3

    Set a repository up

    In the repository, run commitfence init. It writes a commitfence.json with no rules and prints the line to put first in the repository's pre-push hook.

    Terminal
    $ commitfence initWrote <repository>/commitfence.json, with no rules yet. Add rules with commitfence rules add.Add this line as the first command of the pre-push hook (with husky, the file .husky/pre-push):"$(git config --get commitfence.path)" review --hook pre-push "$@" || exit $?exit code 0
    Hook line
    "$(git config --get commitfence.path)" review --hook pre-push "$@" || exit $?

    <repository> stands for the full path of the repository's folder.

    With husky the hook is the file .husky/pre-push. Without it, it is .git/hooks/pre-push, a shell script that starts with #!/bin/sh and holds the line.

  4. 4

    Add a rule

    This rule forbids DateTime.Now. It is for a usage, a place where code refers to a member as the compiler resolved it, and it carries the reason it exists. Writing a rule has the other kinds.

    Terminal
    $ commitfence rules add TEAM012 --for usage --title "Use IClock, not DateTime.Now" --where target=System.DateTime.Now --forbid --why "Code that reads the clock directly cannot be given another time in a check."Added rule TEAM012.exit code 0
  5. 5

    The first refused push

    With the rules and the code committed, a push of a file that breaks them is refused. commitfence review --push says what the hook would say for the current branch, without pushing.

    Terminal · the push is refused
    $ commitfence review --pushsrc/Shop/Invoice.cs(7,9): error TEAM010: No braces around a single-line ifsrc/Shop/Invoice.cs(5,17): warning CA1822: Member 'IsOverdue' does not access instance data and can be marked as static [Shop, net11.0]src/Shop/Invoice.cs(7,28): error TEAM012: Use IClock, not DateTime.NowShop (net11.0): reviewedrefs/heads/main: 3 changed files. Rule files changed: .editorconfig, commitfence.json. 2 changed files of no known language were not looked at. 1 of 1 files reviewed, 1 of 1 builds checked: 2 blocking, 1 warning.exit code 1

    Two rules block this push and one only warns. The push is refused because review ends with exit code 1, and the hook ends with it.

  6. 6

    Fix it, and the push may go

    The same method after the fix: the clock comes from an IClock, and the one-line if has no braces. Staged, the review ends with exit code 0.

    Terminal · the push may go
    $ commitfence review --stagedShop (net11.0): reviewedstaged changes: 1 changed file. 1 of 1 files reviewed, 1 of 1 builds checked: 0 blocking, 0 warning.exit code 0

    Read the documentation →