Managing a FTP-Website with Git
In my case I owned webspace and wanted to manage it with Git. The common way to checkout a git-repo on update or just periodically wouldn't work, because I am not allowed to run code. But it turns out that all you need is Git on a local machine or on another server, and ftp access.return home
1. Initializing a Git Repo
This tutorial builds on this tutorial on toroid.orgFirst thing is to create a Git Repository. In case of this website I initialized it on a server. You could do the same on your local machine. (You'd need to change one command later on).
$ cd example.git/
$ git init --bare
$ mkdir example.org
2. Setting up Git HooksThis hook has to checkout the newest version after accepting it (post-update) and then needs to upload it to your destination webspace via ftp. The best ftp client to upload a whole directory I found was ncftp.
$ nano example.git/hooks/post-update
GIT_WORK_TREE=/home/pi/tibyte_nitrado.net/ git checkout -f
ncftpput -u [FTPUSER] -p [FTPPASSWORD] -R [WEBSITE] / [PATH OF "example.org/"]/*
#e.g. ncftpput -u admin -p 12345 -R www.example.org / /home/admin/example.org/*
3. Pushing changesYou first have to set up your local git directory, for that all you need to do is clone the remote repo.
$ git commit -m "init"
$ git push origin master
PS: every time you push something to the git repo your only your diff's get sent (good), but the repo-server has to send all files to the webspace, because he can't know what the webspace looks like. This means the publishing process, i.e. sending all files over ftp can take a while (bad).
4. Advanced: WorkflowYou don't want to overflow your Git Repo with changes, even more so when even push means that you have to reupload the whole page (I am looking for a way around that. "ncftpput -A ..." might work). To test local files in a nice way you can set up a series of things.
- Set up XAMPP
- Only use HTML, CSS and JS and test it in browser*
- Set up Atom
* might not always be a good idea, because of absolute file paths.I want to talk about the latter.
5. Atom and php-serverI am not involved in the developement of the Atom editor nor am i connected to the plugin php-server, it's just what I use and what I am happy with.