Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Side effects on a periodic git fetch

Let's say i have a code like this:

git fetch &&  git diff origin origin/master --quiet || echo "untracked"

And i want it to run periodically. Let's say, once a second, or once per five seconds and so on.

If this code outputs "untracked", or in other words, if there is an update on the remote,i will run a git pull to update the local code.

Question is: Is it bad to do something like this? I mean, i know that it would be a constant request on the remote server. But, is it bad? And apart from that, is there any other side effects? Thank you very much.

like image 978
Lucas Meine Avatar asked Apr 20 '18 19:04

Lucas Meine


1 Answers

Beside making other commands fail if executed too often, then main drawback of a regular fetch is on the push --force-with-lease.

I have documented as much in "push --force-with-lease by default"

--force-with-lease or --force-with-lease=<refname> interacts very badly with anything that implicitly runs git fetch on the remote to be pushed to in the background, e.g. git fetch origin on your repository in a cronjob.

The protection it offers over --force is ensuring that subsequent changes your work wasn't based on aren't clobbered, but this is trivially defeated if some background process is updating refs in the background.

like image 133
VonC Avatar answered Oct 09 '22 06:10

VonC