Home > Back-end >  git: is it possible to detect changes in REMOTE repository
git: is it possible to detect changes in REMOTE repository

Time:02-28

I have a large number of git repositories to monitor, which I want to know whether there are any changes (in any branch) of them. So I hope to do something like ls-remote, so that I can get this info without clone the repository to local directory.

As a matter of fact, I ONLY want to know if a remote repository has changed since the time I specify (last check), and do NOT care about the exact commit, or branch the change took place (which can be examined later after cloning to local directory).

The reason is that the vast majority of repository I monitor do not change often, and I want to react to changes in repositories as quick as possible.

Also, I do not want to use any server-side hooks.

CodePudding user response:

If the server you're using supports it, the best way to do this is a webhook, since that means the server you're using will explicitly tell you about events, such as pushes, that you're interested in.

If you have a small number of repositories, and you only need this information infrequently, then you can do something like git ls-remote URL | sha256sum to get a single hash that changes when any ref changes. However, this is not suitable for many repositories or frequent polling, because it will put excessive load on the machine and you'll probably end up getting blocked for excessive usage. In such a case, a webhook would be your only option.

  •  Tags:  
  • git
  • Related