Syed Mujtaba Software Engineering Blog

Git-Autocommit : An interesting project using the inotify system call in Linux

2020-10-10

Git Autocommit is a program that can recursively detect changes in a directory and trigger git commands to push those changes to a git repo.

Also, it’s Completely Open Source : Git Repo !

It can be extended to doing anything apart from pushing to git repo as well.

The idea behind it is pretty simple : “Linux will monitor for changes in a particular directory, when changes are detected, git commands are triggered to push them to the repository.”

It Employs inotifywait (a Linux System Call from the inotify family) to recursively watch a directory for changes. Triggers Commands to push changes when they are detected. This script can be easily modified for any VCS / Cloud provider which provides command-line interface.

Linux provides a nice interface for monitoring all file system events like creating, modifying, removing files. The interface is inotify family of system calls, the userspace utilities leveraging these calls are provided by the inotify-tools package in Ubuntu (available on the universe repository). If you don’t have it already, install by:

sudo apt-get install inotify-tools

inotify-tools provides inotifywait and inotifywatch binaries, we need the first one.

It’s written in Bash :

So, to summarize

It’s feasible to build a simple service for Linux that’ll watch a directory for changes and push those changes to the cloud in real time. In our case we used a Linux System Call (inotifywait) and git to implement the same. Many IDE’s too use the same system call to detect changes in a project. Currently it’s just a shell program but we plan to make it a Daemon (Standalone Process) soon.


Content