I'm looking to write a script that monitors all files/folders tracked by git to notify me if any of them have been changed. I'm looking for file changes and not necessarily staged changes.
I've been combing through various SO questions and documentations, but I can't find any relevant examples for implementing a file system watcher based off of git that would be efficient, since I might want to implement this across a multitude of repositories and possibly hundreds of files all on one system without being extremely inefficient.
Is git even the right solution for this? Would I be better off using fswatch
even across many, many files?
Many thanks
Git itself doesn't watch the file system (*) and as such also doesn't provide any hooks when files change. It only inspects the file system whenever a git command is executed.
Therefore there aren't (and can't be) any hooks that execute on file change. You'll need to find another way to watch the file system, if you need this.
(*) Apparently there is a way to actually use file system monitoring in git, but that only seems to be used to speed up git status
(and other operations) and still doesn't mean that git actively monitors changes. It just replaces "check each file for modification" with "check the list of changed files since the last time for modification".