How to deploy files from a git repository via FTP

| | 2 min read

Git is very popular guy in the world of version control systems and it is distributed by nature Without using a VCS, handling a project's multiple versions will get you in trouble very often. If multiple people are working on same project, this may be thousand fold. But if your client's service provider only gave you ftp access and it happens quite often, so you have to handle the project without the help of git. But we can track files easily using git-ftp, without having ssh access to the server.

Steps to install git-ftp

Clone the git repo of git-ftp into your system

git clone https://github.com/resmo/git-ftp.git

Install git-ftp, using the following commands


cd git-ftp
git checkout master
sudo make install

Also make sure that curl is installed in your system. Now let us just walk through the topic how to use git ftp. We can divide the entire scenario into 3, they are initial deployment, maintenance and changes

Initial deployment

Inialize your git repo amd made your initial commit as usual. Now use the following command to push first time to your server using git-ftp

git-ftp init -u username -p - ftp://host.example.com/public_html

Git ftp is tracking the files by uploading the changed SHA1 name to the file.git-ftp.log.

Maintenance

If your server has uploaded files already and you have to track it using git-ftp, download all files and inialize git repo. Then use the following command.

git-ftp catchup ftp://host.example.com/public_html

This will upload .git-ftp.log file into the server and it will help to remember the current state.

Changes

If you modified the code and to add modified files in to the server, just add and commit those file in git way and run the following command.

git ftp push -u username -p - ftp://host.example.com/public_html

You can add default using git config as follows


git config git-ftp.user ftpusername
git config git-ftp.url ftp.hostname
git config git-ftp.password ftppassword
git config git-ftp.syncroot path/dir

After setting default, you don't have to bother about anything, simply run as git ftp push. Also you can add scopes and can add the files to be ignored by adding them into .git-ftp-ignore.

Reference:
https://github.com/resmo/git-ftp/blob/develop/man/git-ftp.1.md