I'm thinking about setting up a cronjob for fetching all my repositories every once in a while, to have the current status ready in case I'm offline. Something like the following (wrapped for better readability):

find $HOME -name .git -type d -printf "%h\0" |
  parallel --gnu -0 --delay 0.2 --jobs 100 --progress \
  'cd {}; git fetch --all --quiet'

I don't really care what happens if the fetch fails -- it might succeed the next time. Perhaps error output could be logged. My questions are:

  • What if the background process fetches into a Git repository while I'm committing to it?
  • Can you recommend other switches to parallel to make this really fail-safe?
  • Given that git is for multi-user collaboration and it was written by Linus... I can't imagine there isn't a git-lock somewhere. It would require testing to find out though. May 20, 2014 at 10:29
  • 1
    @hbdgaf Yes it does, it creates .git/index.lock. But I don't think the lock file is created when using fetch. Probably because fetch --all is harmless and doesn't do any modification to your local tree whatsoever.
    – Dan
    May 20, 2014 at 15:29
  • You could clone every repository locally (i.e. have one clone for this job to work on and another for you to work on)... Jul 8, 2015 at 15:47

1 Answer 1


I've been fetching my local Git repos in the background for two years now, without any sign of trouble. Currently, crontab contains something like

savelog -n -c 400 ~/log/git-fetch.log
find ~/git -type d -execdir [ -d '{}/.git' ]  \; -print -prune |
    parallel --gnu --keep-order \
    "date; echo {}; cd {}; git fetch --all --verbose" \
    >> ~/log/git-fetch.log 2>&1

(but in one line).

  • Is this the final script you used or there is an update? thanks
    – Eyal Levin
    Sep 29, 2016 at 13:03
  • Pasted final version.
    – krlmlr
    Sep 29, 2016 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.