gitwatch-rs

Crates.iogitwatch-rs
lib.rsgitwatch-rs
version0.1.1
created_at2024-12-23 21:19:30.344001+00
updated_at2025-07-31 20:00:01.60051+00
descriptionCLI to watch a git repo and automatically commit changes
homepage
repositoryhttps://github.com/croissong/gitwatch-rs
max_upload_size
id1493425
size218,448
Jan Möller (croissong)

documentation

README

gitwatch-rs

Watch a Git repository and automatically commit changes

GitHub Release codecov

A Rust implementation of the original gitwatch script - with a few additional features.

Features

  • Watch a local Git repository and automatically commit changes

  • Optionally push to a remote

  • Use a custom commit message or generate one via a script

  • Configure a debounce time to limit commit frequency

Usage

Basic usage:

gitwatch watch /path/to/repo --commit-message "Auto commit"
Example use case

I use gitwatch to watch my local notes repository and generate commit messages using aichat.
The example folder contains a small repository demonstrating this use case: Example use case

Configuration

❯ gitwatch watch --help
Watch a repository and commit changes

Usage: gitwatch watch [OPTIONS] [REPOSITORY]

Arguments:
  [REPOSITORY]  Path to the Git repository to monitor for changes [default: .]

Options:
  -m, --commit-message <MESSAGE>
          Static commit message to use for all commits
      --commit-message-script <SCRIPT>
          Path to executable script that generates commit messages.
          The path can be absolute or relative to the repository.
          The script is executed with the repository as working directory
          and must output the message to stdout.
      --commit-on-start <COMMIT_ON_START>
          Automatically commit any existing changes on start [default: true] [possible values: true, false]
      --debounce-seconds <DEBOUNCE_SECONDS>
          Number of seconds to wait before processing multiple changes to the same file.
          Higher values reduce commit frequency but group more changes together. [default: 1]
      --dry-run
          Run without performing actual Git operations (staging, committing, etc.)
  -i, --ignore-regex <IGNORE_REGEX>
          Regular expression pattern for files to exclude from watching.
          Matching is performed against repository-relative file paths.
          Note: the .git folder & gitignored files are ignored by default.
          Example: "\.tmp$" to ignore temporary files.
      --log-level <LOG_LEVEL>
          Set the log level [default: info] [possible values: trace, debug, info, warn, error]
  -r, --remote <REMOTE>
          Name of the remote to push to (if specified).
          Example: "origin".
      --retries <RETRIES>
          Number of retry attempts when errors occur.
          Use -1 for infinite retries. [default: 3]
  -w, --watch <WATCH>
          Enable continuous monitoring of filesystem changes.
          Set to false for one-time commit of current changes. [default: true] [possible values: true, false]
  -h, --help
          Print help

Config file

Most options can also be configured in a gitwatch.yml file located at the root of the watched repository. See docs/gitwatch.example.yaml for reference.

Tips

Disable GPG commit signing for your watched repo

If you've enabled gpgsign globally, you might want to disable it for the watched repositories, since gitwatch uses your regular git user to create the commits.

  1. Add an include to a custom .gitconfig file to your local gitconfig:
    # cd /path/to/repo 
    git config --local include.path ../.gitconfig
    
  2. Create a .gitconfig file (which can be committed):
[commit]
  gpgsign = false
Run as systemd service

Create a systemd user service file gitwatch@.service:

[Unit]
Description=Watch a Git repository and automatically commit changes

[Service]
ExecStart=/usr/local/bin/gitwatch watch %I
ExecStop=/bin/true

[Install]
WantedBy=default.target

I recommend you use it in combination with a config file, then you only need to pass the repo dir as argument:

systemctl --user start gitwatch@$(systemd-escape /path/to/repo/).service

There's also a Nix module, which provides a home-manager service:

inputs = {
   gitwatch-rs.url = "github:croissong/gitwatch-rs";
};

...
  
imports = [ inputs.gitwatch-rs.modules.gitwatch ];

services.gitwatch = {
  notes = {
    repo_path = "${config.home.homeDirectory}/notes/";
    args = [ "--log-level=debug" ];
    extraPackages = with pkgs; [
      bash
      coreutils
      git
      aichat
    ];
  };
}

Installation

Nix

A flake.nix is available for Nix:

  inputs = {
    gitwatch-rs.url = "github:croissong/gitwatch-rs";
  };
  # Reference the package as `inputs.gitwatch-rs.packages.<system>.default`
}
Arch Linux
# TODO: Add AUR package installation instructions
Ubuntu
# TODO: Add Ubuntu package installation instructions
Cargo

Install from crates.io:

cargo install gitwatch-rs
Docker

Docker images are published to the ghcr.io/croissong/gitwatch-rs:

docker run -v /path/to/repo:/repo ghcr.io/croissong/gitwatch-rs:latest /repo
Binaries

Precompiled binaries are available for Linux and macOS from releases.

Shell completion

Shell completion scripts for bash, zsh, fish & more can be generated via:

gitwatch completion <SHELL>

Credits

This is a Rust implementation of the original gitwatch bash script.

Contributing

Contributions are welcome! Feel free to submit a Pull Request.
See CONTRIBUTING.md for development hints.

Commit count: 0

cargo fmt