{ pkgs, ... }:
{
  programs.git = {
    enable = true;
    # Don't use difftastic on git-diff by default
    # it makes distributing patches difficult
    #
    # Instead use difftastic as a difftool
    difftastic.enable = false;

    userName = "Anthony Cicchetti";
    userEmail = "anthony@anthonycicchetti.com";

    aliases = {
      pushall = "!git remote | xargs -L1 git push --all";
      pr = "!f() { git fetch -fu $${2:-$(git remote |grep ^upstream || echo origin)} refs/pull/$1/head:pr/$1 && git checkout pr/$1; }; f";
      logp = "log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short";
      difft = "difftool";
    };

    extraConfig = {
      core = {
        autocrlf = "input";
        fsmonitor = true;
      };

      checkout = {
        workers = 0;
      };

      diff = {
        tool = "difftastic";
        algorithm = "histogram";
        submodule = "log";
      };

      difftool = {
        prompt = false;
        difftastic = {
          cmd = "${pkgs.difftastic}/bin/difft --color auto --background light --display side-by-side \"$LOCAL\" \"$REMOTE\"";
        };
      };

      fetch = {
        prune = true;
        fsckObjects = true;
        pruneTags = true;
      };

      format = {
        pretty = "fuller";
      };

      help = {
        autoCorrect = "prompt";
      };

      init = {
        defaultBranch = "main";
      };

      log = {
        follow = true;
      };

      merge = {
        conflictStyle = "zdiff3";
      };

      pack = {
        allowPackReuse = "multi";
      };

      push = {
        autoSetupRemote = true;
      };

      pull = {
        rebase = true;
      };

      rebase = {
        updateRefs = true;
      };

      receive = {
        fsckObjects = true;
      };

      rerere = {
        enabled = true;
      };

      status = {
        submoduleSummary = true;
      };

      submodule = {
        recurse = true;
      };

      transfer = {
        fsckObjects = true;
      };
    };

    includes = [
      { path = "~/.gitconfig_local"; }
    ];
  };
}