7

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.

Lucas Meine
  • 1,524
  • 4
  • 23
  • 32
  • Are you going to never switch the local branch? Are you never going to commit a change? – choroba Apr 20 '18 at 20:03
  • @choroba Yeah, that's right. I just want to pull stuff, never commit. – Lucas Meine Apr 20 '18 at 20:04
  • Running a git command creates and delete the '.git/index.lock' file. Running multiple git commands in parallel into the same repository will make some calls to fail quite often... But if you run it each 2 minutes could be OK. – Philippe Apr 20 '18 at 21:54
  • @Philippe Worth noticing that they wont run in parallel. One will run just after the other. – Lucas Meine Apr 21 '18 at 01:58
  • @lukas I would like to say you won't be able to run any other git command in this repository once you start your script. – Philippe Apr 21 '18 at 07:48

1 Answers1

5

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250