How do I keep my local files in sync when I make changes on the website panel?

Hi,

I have recently made a website using Kirby. I currently update my code changes via SFTP. I use the web panel to update my projects page. Thus, my local files do not mirror the changes on the web, is there any method for me to fix this?

And/or a method to keep my kirby files in sync in general, without me having to use a client like FileZilla?

Thank you.

Regards,
Vivek.

Have a look into rSync. It can push / pull between two computers either locally or remotely. You can tie it into a NPM script for easy deploys.

Another way is to use Git, so when you commit it will publish to the live server.

2 Likes

Hi Jim,

Thanks for your reply. I’m more inclined to learning how I could do it with Git, is there a tutorial I could follow?

Afraid not :slight_smile: i roll with rSync

i mean there might be a guide for the Git way out there, i just never had the need for one… @texnixe might be able to help here

1 Like

Alright, looks like I’m going to see if I can get this working with rSync, thanks for all your help!

i do with with a bash script and trigger it from NPM scripts…

which means i can type yarn deploy:live and off it goes.

You could use my Versions plugin, which uses Git internally.

Hi, Lukas!

I followed your tutorial on GitHub, and I think I’ve successfully installed it, I see a versions tab under the panel burger menu.
Would I be correct in assuming that when I push changes to my Git repository it will reflect on my site? Or is this just more for version control, and if so, how do I sync the current version on my site to the local one?

Regards,
Vivek.

The plugin itself is for version control, but since it uses a Git repo under the hood, you can use Git to sync the versions.

I have a tutorial on automatic backup to a remote Git repo: Remote backup · lukasbestle/kirby-versions Wiki · GitHub

You can extend that to also pull the repo (including tags) in the cronjob. Alternatively you can set up your repo on the web server as a remote for your local repo and pull/push directly.

Please keep in mind that the Versions plugin only displays Git tags, not individual commits. Easiest would be to use the plugin locally as well to create versions.

Hi,

I don’t know what happened but on the localhost:panel I get the following error when I click on Versions

The content directory of instance Local is not a worktree of the content directory of the current site, please connect the two instances as worktrees"

And on the live website panel I get the following error

A Git error occurred: Unknown option: -C usage: git [–version] [–exec-path[=GIT_EXEC_PATH]] [–html-path] [-p|–paginate|–no-pager] [–no-replace-objects] [–bare] [–git-dir=GIT_DIR] [–work-tree=GIT_WORK_TREE] [–help] COMMAND [ARGS]

Can you help me on how to fix this?

As for your tutorial, I’m not sure if I would be able to follow it correctly :frowning:

The local and live instances don’t “see each other”, so you cannot configure both instances locally. The local installation should only have the “local instance” configured and the live installation only the “live instance”.

I’m pretty sure the Git version on your server is too old. The plugin requires Git 2.5+ (ideally newer).

Thank you, Lukas,

I’m sorry for so many questions but I don’t know how to do this

Is there a tutorial I can follow to fix this?

As for the second part, I use Namecheap if that’s what you mean by server? The Git installed on my machine is the newest.

I’m pretty sure the Git version on your server is too old. The plugin requires Git 2.5+ (ideally newer).

I’m sorry, but I feel like the Versions plugin is not the right fit for your setup.

rSync as suggested by James may be better suited as it doesn’t require much initial setup. There are also GUI tools for rSync available (depending on your operating system). I don’t have personal experience with either of those however.

1 Like

Alright, I’ll try this instead, thank you for all the help!

If you do go the rSync route, the version bundled with MacOs isnt the most current. Easily fixed via homebrew though.

rSync does require a host that supports SSH connections, as it does the transfer over a secure SSH tunnel. A lot of super cheap shared hosts dont allow this, but easy enough to find one that does. Its worth doing though, as its roughly 10x faster than SFTP and after the first push, it will only transfer the files that have changed.

If you want to understand whats going on with rSync, heres a crash course. Sync large quantities of files or directories between local machine and server with rsync

Thats pretty much all you need to know.

1 Like

I should also point out one gotcha with rSync. It does a 1:1 mirror from source to target. It will delete stuff on the target that does not exist on the source. Its possible to deploy to the server from your local machine, and also in the other direction.

The gotcha is that Kirby numbers folders in the content folder. If the pages have been reordered on the server and you pull from remote to you local machine, you can end up with duplicate folders with a different number prefix in rare occasions.

I use Git for version control and to combat this, i do a commit locally to git, then manually trash my entire content folder from my local copy. Then i do an rSync from remote to local. This gives me a good copy of the the content folder. then i commit and work on my changes, before pushing back the other way to the live server.

I hope that makes sense.

1 Like

Thank you so much for the detailed response, @jimbobrjames! Really appreciate you.
I’m going to go through the link you sent me and see if I can figure it out because using SFTP is proving to be a massive pain especially when the changes are pretty incremental. I google’d it and Namecheap does support SSH in the cPanel so hopefully I’ll be able to get this thing working! :slight_smile: