2

This might sound like a stupid question, and the use-case is rather simple, but I haven't been able to find a decent and simple solution. In short:

I have a Bitbucket repo that I want to have synced to a local folder on my local server. So whenever there's an upstream change, the most updated version of the file must be copied to the local folder. There is never a push/commit from local-to-cloud, it's merely a 1-way read-only sync.

Thanks in advance for any suggestions! (maybe the solution is so obvious that I don't see it?)

Dan Bonachea
  • 2,408
  • 5
  • 16
  • 31
Dimster
  • 31
  • 2

1 Answers1

0

You don't explain what software is running on your local server, but assuming this is some flavor of UNIX/Linux/macOS and you have crontab access, the easiest thing is probably to just schedule a cron job to pull updates.

A command like the following will schedule a git update every 60 seconds, logging the output to a file:

echo '* * * * * cd $HOME/path/to/git/workdir && git pull -q --ff-only >> update-log 2>&1' | crontab 

Note 1: This assumes your user currently has an empty crontab on the server, if you don't then you should instead use crontab -e to manually append the directive to your existing crontab.

Note 2: You'll need to ensure your account on the server has permission to access the BitBucket repo without a tty connection (e.g. without SSH agent forwarding), so you might need to fiddle with authentication to set that up (which is beyond the scope of this answer). For a public BitBucket repo, cloning via HTTPS without a user name is probably the simplest approach, since no authentication is required.

Note 3: The first * in the directive above can be adjusted to select a different polling frequency, e.g. 0,15,30,45 for every 15 minutes. If you omit the 2>&1 then you should get an email for any errors (assuming SMTP is configured on the server).

Note 4: The git command embedded above assumes you never rewrite history in the upstream git repo or manually modify the local directory. If either is a possibility, then you might instead want to use git pull -q --rebase or even git fetch && git reset --hard '@{upstream}'

Dan Bonachea
  • 2,408
  • 5
  • 16
  • 31