Using Git to FTP Your Project
Tags: git, ftp, webdev, productivity
Published: 2019-04-22 19:39:31

---
title: Using Git to FTP Your Project
published: true
description: How to FTP through Git
tags: #git #ftp #webdev #productivity
---


<p>Git has become a version control standard and for good reason. Its ability to branch projects, track and roll back changes makes development MUCH easier!</p>



<h2>The Gap Between Git and FTP</h2>



<p>When developing at some point you upload your work to a server. FTP usually does the trick and there's a couple of ways to deploy your work:</p>



<p><em>A) Upload ALL the files. </em><br>Sure, everything gets uploaded, but it can be time consuming and sometimes files get overwritten that shouldn't.</p>



<p><em>B) Only upload changed files. </em><br>That makes more sense except keeping track of&nbsp; which files have been changed can be messy.</p>



<p>Git knows which files have changed and you've been working with it the whole time, <strong>can't we just use Git to FTP?</strong></p>



<p>No, it doesn't work that way.&nbsp; &nbsp;Git is a version tracker not a file manager. You could install Git on the live server, but sometimes that's not practical.&nbsp; With Git, FTP is out of reach.</p>



<h2>Git-ftp:&nbsp; Bridging the Gap</h2>



<p>This is where Git-ftp comes in.&nbsp; It's a plug-in that adds a set of commands to&nbsp; Git allowing you to upload your changed files via FTP.&nbsp;  </p>



<p>As its <a rel="noopener noreferrer" href="https://git-ftp.github.io/" target="_blank">website</a> says:</p>



<blockquote class="wp-block-quote"><p> If you use Git and you need to upload your files to an FTP server, Git-ftp can save you some time and bandwidth by uploading only those files that changed since the last upload.</p><p>It keeps track of the uploaded files by storing the commit id in a log file on the server. It uses Git to determine which local files have changed.</p><p>You can easily deploy another branch or go back in the Git history to upload an older version. </p></blockquote>



<p>Well, that covers it, now doesn't it?</p>



<p><strong>The git-ftp website: </strong><a href="https://git-ftp.github.io/" target="_blank" rel="noopener noreferrer"><strong>https://git-ftp.github.io/</strong></a></p>



<h3>Note: Git-ftp Is Not A Repo On Your Server</h3>



<p>Git-ftp doesn't make your server a proper repository! Git is not installed on your server, git-ftp simply tracks changed files and uploads them.&nbsp; You can upload different branches (which is great!), but you can't pull changed files from your server.&nbsp;&nbsp;<br>Honestly, I've never found these restriction to be a problem.</p>



<p><strong>Think of git-ftp as a way to manage ftp uploads not version control.</strong></p>



<h2>How to Use git-ftp in Your Work Flow</h2>



<p>I've been using git-ftp for a while, and found it smooths out the work flow.&nbsp; For example, let's say I'm adding a new code called FeatureA to an existing project.</p>



<p>The process:</p>



<ol>
<li><strong>Create a new branch called 'FeatureA' in development</strong><p>There's no need to pull from the server since it's not a repository.&nbsp; The official repository is in development.</p></li>
<li><strong>Build and test in development.</strong><p>The code works like a charm!</p></li>
<li><strong>Deploy to the live server.</strong><p>A simple command: &nbsp;<em>git ftp push</em> will send the new branch files to the server.</p></li>
<li><strong>Test on the live server</strong><p>Uh-oh!&nbsp; Doesn't work as expected, un-do this quick!</p>
<ol><li><strong>Reinstate the 'master' branch</strong><p>Push the branch 'master' to the live server.&nbsp; Branch 'FeatureA' is gone.&nbsp; Back to the drawing board.</p></li>
<li><strong>Fix the problem, try again.</strong><p>Push branch 'FeatureA' to live server and test.<br>It works! Happy Dance!</p></li>
</ol></li>
<li><strong>Merge with 'master'</strong><p>I have a personal rule that the live server only uses the 'master' branch.&nbsp; <br>I found if I had another branch live, it was too easy to lose track of which branch was being used.&nbsp; So, now I'll upload another branch for testing only, but once it checks out, it gets merged into 'master' and 'master' get pushed to the live server.<br>If there is a problem I can still roll 'master' back to before the last merge.</p></li>
<li><strong>Client review and approval</strong><p>I keep branch 'FeatureA' on hand until the client has signed-off on it.&nbsp; <br>Even after it's approved, I'll re-name the branch to something like 'FeatureA_done'.&nbsp; That keeps the branch around in case I have to go back to it, but the '_done' tells me it is disposable.&nbsp; I usually get rid of it when I'm sure the change is good.</p></li></ol>



<p>Although this process may not be ideal for all cases, I have used it for a while and it works for me.&nbsp; I can use Git functionality and deploy through FTP with minimal friction. The other thing I like, is it's a sure thing.&nbsp; If you're working with a new server, as long as you can FTP, it should work.&nbsp; You don't have to spend time configuring the server to run Git etc.&nbsp; Just focus on your code!</p>