A vital part of any project comes at the end when you need to push all of your code and assets onto a live server, and publish your work. Not only that, but you need to ensure that further bug-fixes and feature requests can be deployed easily too.
Especially if you’re limited to only FTP or SFTP access on your deployment server, you can quickly find the constant development/deployment cycle taking up a lot of time as you try to keep on top of what’s changed locally against what’s changed remotely.
Some things to consider when setting a project live:
In my case, I keep all of my code versioned within a Git repository. And if a project consists purely of file-based content, this simplifies things and you may find the following solution of use.
git-ftp is an FTP client written as a shell script, so that it can be executed from the command line, and deploys directly via FTP, transferring only the recently modified files and leaving all others untouched, unless explicitly instructed otherwise.
Depending on the specifics of your project and your server configuration, you may not have full access to root-level features such as shell access. This can be the case if your deployment location is hosted on a shared server environment, or otherwise locked down system. This usually means that you won’t have access to tools such as the command-line
git tool which could otherwise be utilised to deploy project files.
If that’s the case, then it’s likely that the only direct access you’ll have to the filesystem is via a (S)FTP connection.
This solution deals with cases where you are both:
You can find everything required to install and configure
git-ftp over on its Git page here.
Initial setup is straightforward – once installed in a suitable location (on my Windows machine, for example, I have it installed within a Git shell) you can store the appropriate configuration settings within your project’s
.git/config file. This means that you can store all of your project deployment settings, and track them via version control. Very handy!
Configuration is straightforward. You can see plenty of examples on the man page here
For example, to set the username, FTP address and password,
$ git config git-ftp.user robin $ git config git-ftp.url ftp.solarisedesign.co.uk $ git config git-ftp.password yeahLikeIdPutThatHere
There are other settings, detailed on the man page, which concern SFTP authentication and SSH keys which you can set up to avoid sending details over an insecure connection.
Once configured, the process is fairly straightforward and can be initiated via the command line with the
git ftp command.
git-ftpchecks your local repository for changes. If any are found, it prepares the transfer
git-ftpknows which files have been modified or deleted since the last transfer
git-ftptransfers any changed or new files, and deletes any old ones on the remote server.
For example, say you have the following files in your project
file1.txt file2.php file3.jpg
You run an initial transfer by executing the command,
git ftp init -v
This prepares the remote deployment location by initially uploading all files from the repository, regardless of their change status. The
-v flag is there to provide additional feedback information, otherwise I found that for large uploads, the lack of progress information means it’s difficult to gauge how long the proess will take.
Transfer [file1.txt, file2.php, file3.jpg] --> remote server
Along with your files,
git-ftp also uploads a log file containing the SHA hash of your latest commit.
Then say we modify some of our files,
file1.txt *file2.php* [modified] ~file3.jpg~ [deleted]
Now, we run the command,
git ftp push -v
This then checks the uploaded log file on the server to determine what, if anything, has changed since the last transfer. It should see that
file2.php has been changed and
file3.jpg has been deleted. It then connects via FTP again and transfers the new
file2.php and deletes the remote copy of
Transfer [file2.php] --> remove server, Delete [file3.jpg]
There are some other aspects of
git-ftp which could come in handy for more complex projects
.git-ftp-includefiles. These two files can be used to ignore, and include respectively, files in your project that you either want to leave out of the FTP transfer (e.g. environment-specific configuration settings) or include if they aren’t part of your git repository
Check out the man page for more details.
There are a couple of limitations when using this method,
git-ftp. Any changes that are made run the risk of putting the site out of sync with the repository
Also, it’s not so much a limitation, but this process requires that you have commited all changes to your git repository prior to running the command. This could be a little frustrating initially if you’re not accustomed to frequently commiting your code and need to test frequently on the remote deployment server, but I find it’s a useful reminder to commit often, and gets you into good practice.
This method also wouldn’t cover content if your site is powered by a database (although this is a problem common to deployment and maintenance with any site that runs a backend database anyway – you’d need to look at more thorough tools to manage database deployment cleanly)
My own site is powered by Statamic, an entirely file-based system, so I find this
git-ftp deployment method to be a really nice fit. Especially as it’s just myself working on it, it’s a real timesaver – and good practice – to be able to commit the latest changes and throw everything up immediately to the server with a single command.
Generally speaking, I find
git-ftp a very useful tool to ease my deployment process. For my purposes if provides everything I need it to, and I’d likely consider using it on projects with small teams too.
If this is the sort of thing that you think may benefit your own project, feel free to get in touch to ask me any questions you might have.
Robin is the dedicated developer behind Solarise.dev. With years of experience in web development, he's committed to delivering high-quality solutions and ensuring websites run smoothly. Always eager to learn and adapt to the ever-changing digital landscape, Robin believes in the power of collaboration and sharing knowledge. Outside of coding, he enjoys diving into tech news and exploring new tools in the industry.
If you'd like to get in touch to discuss a project, or if you'd just like to ask a question, fill in the form below.
Send me a message and I'll get back to you as soon as possible. Ask me about anything - web development, project proposals or just say hi!