Copy repository to file hosting service, e.g. Nextcloud

Is it possible to automatically clone a repositories to a file hosting service such as Nextcloud?

Most likely yes, but it depends mostly on the hosting service which you’re targetting.

Continuous Integration services like Travis CI support deploy functionality, which means that you could execute a script that copies your repository contents to a hosting service via FTP, or other protocols supported by the hosting service. This would be triggered every time you commit to master branch (or any other branch of your choice), which is usually what one is looking for, instead of regularly copying the whole repository at fixed intervals even if there were no contents changes.

But you need to consider many critical aspects, the most important being the need to store your credentials to access the hosting service — you wouldn’t want those to be stored in the deploy script, which would expose them in your source repository and its copy as well. Instead you need to setup some protected environment variables which are available to the CI service but never shown publicly. And you must also make sure these are protected as “secret” variables, so they won’t be exposed in the script log by accident or during an attack.

It requires some careful setup and testing, and you also need to check if the hosting service which you’re targeting allows you to do this — i.e. depending on their EULA, you might or might not be allowed to share your credentials with third party services, so make sure you read carefully you’re contract with them.

The easiest way to achieve this is by doing it on your local computer, so you don’t need to store the deploy script in the repository, nor your hosting credentials anywhere. Of course, this has some limits because unless your local PC is running 24/7 it might not guarantee real time updates (in case others are also committing to the repository).

But yes, it should be doable. Some links you might want to read: