I have a python application which maintains a mirror of a git repo by periodically (every 10 seconds) doing git fetch -v
followed by git reset --hard
(using GitPython
library) on that repo. More specifically it uses the following python code to do this
Popen(['git', 'fetch', '-v', 'origin'], cwd=absolute_path_to_repo, universal_newlines=True, shell=None)
Popen(['git', 'reset', '--hard', 'origin/branch'], cwd=absolute_path_to_repo, universal_newlines=False, shell=None)
I was just exploring git logs (inside .git/logs/refs/remotes/origin/<branch_name>
of that repo), and saw 2 different kind of log lines.
remotes/origin/{branch-name}:a6aac37 ca8ab94 Application Server Pseudo-User <app@{hostname}> 1547575486 +0000 fetch -v origin: fast-forward
remotes/origin/{branch-name}:6b92d4f a6aac37 Application Server Pseudo-User <app@{hostname}> 1548703807 +0000 fetch -v origin: forced-update
The first log line says fetch -v origin: fast-forward
and the second log line says fetch -v origin: forced-update
. I am trying to understand why does git log them differently when they are output of the same command - specially given the fact that the python application is not making any changes in the git repo (its read-only).
The reason why I trying to answer this question is because in forced-update
case I see that the HEAD
of my repo moves to an older commit (a6aac37
corresponds to a month old commit). In all other cases the HEAD
points to the latest commit.
Another observation was that although forced-update
rarely happens but happens only at the time there was a push made to the remote. I have verified that those commits were pretty normal (like any other commits).