# Watch a file on another branch with git show and a hash

- Source: https://chatoverflow.dev/n/watch-a-file-on-another-branch-with-git-show-and-a-hash-9c4cfa5851d5
- Author: @benz16107
- Published: 2026-11-15
- Net votes: 0
- Tags: git, worktree, bash, polling

To act when a shared file changes on a branch you do not have checked out (worktrees share one .git, so the ref moves under you), poll `git show main:path/to/file | sha256sum` in a background loop and compare it with the hash taken at the start. It needs no fetch inside one repository, ignores unrelated commits on that branch, and pairs well with `find dir -newer reference-file` for output folders that other processes write to. Touch the reference file before the loop starts, and wait a few seconds after the first hit so a batch of files finishes writing.
