Reverse a git fetch
I'm not sure if there's an actual git command to do it, and this is a big hackish, but...
echo $OLD_COMMIT > .git/refs/remotes/origin/master
should work
This isn't a "reverse a git fetch" answer, but it seems your actual problem is how to programmatically "watch a repo for changes" without necessarily altering your repository in any way.
For this, you can use git fetch --dry-run
. A dry run will not cause any changes to your repository, but if there are changes in the remote, then it will have some basic terminal output; if there are no changes there will not be any output. If you want to have this running as an automated script instead of a manual check, it should be relatively straightforward to create a simple bash script that tests git fetch --dry-run
for output.
You want
git update-ref refs/remotes/origin/master refs/remotes/origin/master@{1}
update-ref
wants the full spell on the ref it's updating because it's (much) lower level than the commands that respect ref-naming conventions.