Push Git to FTP

With some lightweight web-releated project, I often found that pushing a particular Git revision to the production server – forming a Git to FTP bridge – could be a really convenient part of the workflow. For example editing/versioning the theme for this blog is this kind of issue.

Having a custom action pushing git to ftp at your fingertips can simplify production code deployment.

Having a custom action pushing git to ftp at your fingertips can simplify production code deployment.

I’m using SourceTree (for Mac OSX) to manage my Git repositories, which has a “Custom Action” feature fortunately that can execute shell scripts with some parameters passed in about the current repository (actually about the current working copy).

In the meanwhile René Moser made a useful command-line tool to called git-ftp (surprisingly) to perform the same task I outlined above. I’d prefer a GUI setup, though, that is more close to my workflow.

So the only thing left is to hook up these parts together. I’m thinking of writing a step-by-step tutorial here, since I could be exhausting to get these things together for people like me without a reliable knowledge on weird terminal commands and pesky shell scripts.

0. Show hidden files.

Type into terminal (at any location):

defaults write com.apple.Finder AppleShowAllFiles YES
killall Finder

1. Install git-ftp (will be installed in /usr/local/bin).

Type into terminal (at any temporary download location):

git clone https://github.com/git-ftp/git-ftp.git
cd git-ftp
git checkout master
sudo make install

Or you can check a more complete installation guide at the git-ftp project page INSTALL.md. Not that you’ll need administrator (super user) access for the last command.

2. Add a tiny shell-script (bridge between SourceTree and git-ftp).

Grab (or create) these – gitFtpInit.sh, gitFtpPush.sh (also find gitFtpInit.bat, gitFtpPush.bat for Windows by Mools Gang) – shell script, and put it near you brand new git-ftp installation in /usr/local/bin.

Seems you have to restore the scripts’ chmod to work properly, so make them execuable using chmod.

chmod +x /usr/local/bin/gitFtpInit.sh
chmod +x /usr/local/bin/gitFtpPush.sh

Thanks, Frédéric.

3. Configure Custom Git to FTP Action in SourceTree.

Open SourceTree Preferences/Custom Actions then Add.
In SourceTree preferences create a custom action by providing some basic setting.

Configure Custom Git to FTP Action in SourceTree

Add a name for the action, a path to the script from step 2., then provide some parameter hooks to the script: $REPO (FTP username) (FTP password) (FTP path).

Note that you not just provide the FTP host but the full FTP path where you want to deploy your code. Something like ftp://<FTP host>/<path to directory>. Also checking Show Full Output is a good idea to see git-ftp responses/process.

4. First run (let git-ftp setup some stuff on FTP)

For the first time git-ftp need to do some setup at your FTP server. So you should run the action with the initialization script gitFtpInit.sh (only for the first time!), so change it temporary in your action definition.

Configure Custom Git to FTP Action in SourceTree

For the first time, you should run the initializer script (gitFtpInit.sh) instead of the push script you’ll be using anyway.

Run the action, see it initialized, be happy.

SourceTree Custom Git to FTP Action with git-ftp

A pretty handy way to launch such action is just by a right click on a particular revision.

You should undo the changes you’ve made in action definition, so write back the script name to gitFtpPush.sh, and done.

Having this you can easily push your latest state of your working copy to the FTP you specified. Be warned that git-ftp expects that no other people (nor you) is going to modify the deployed files in any other way than pushing with this tool (as you can see this stated in Limitations section of the project page).

  • Hi,
    Thanks for the tut!
    But the two .sh files are not available anymore.
    Can I have access to this please?

    • eppz

      Thanks for the spot, just fixed the URLs.

  • Hi again !
    Thanks for files !
    I’ve tried your method but I’ve got this error message

    git LocalPath userName Psswd RemotePath (variables are well implemented, that’s just for the example …)
    launch path not accessible
    Completed with errors, see above

    Do I miss something ?
    I’m sorry, I’m a beginner with GIT, Sourcetree …
    Really thanks for your help !

    • eppz

      Probaly the launch path is not accessible. 😀
      Double check everything:
      Is git-ftp properly installed at /usr/local/bin/?
      Do you typed the same path at ‘Script to run:’ field /usr/local/bin/gitFtpPush.sh?
      Do you have administrator (super user) privileges?

      • Hi,
        thanks for your answer !
        I’ve took my time to try to solve my problem.
        Unfortunately, I’ve removed all my install and do it once again.
        I’ve installed homebrew, grep … and then git-ftp but I’ve always got this error :

        git /Applications/MAMP/htdocs/Folder username password ftp://ftp.url.com
        launch path not accessible
        Completed with errors, see above

        Is git-ftp properly installed at /usr/local/bin/? > only an exec file. Is it OK?
        Do you typed the same path at ‘Script to run:’ field /usr/local/bin/gitFtpPush.sh? > Yep! And tried with the Init file for first time.
        Do you have administrator (super user) privileges? > Yep! I’m admin.

        Is there something I need to do on Mountain Lion to install GIT or something else?
        Thanks for your help.
        That drives me crazy 🙁

        • eppz

          Scripts need to be set executable (I think something gone wrong during downloading):
          chmod +x /usr/local/bin/gitFtpInit.sh
          chmod +x /usr/local/bin/gitFtpPush.sh

  • Hi,
    I’m sorry but I really not achieve to get your script work 🙁
    I’ve tried everything but nothing work. I always get this message “launch path not accessible”.
    Do you know what can be the problem ? My Mac install maybe ?
    Thanks for you help.

  • Hey,
    How are you?
    Your last trick made the stuff works. No “launch path …” anymore !
    Now i’ve got another pblm :

    git /Applications/MAMP/htdocs/XXX username psswd ftp://ftp.XXX.XXX/www/
    Switching directory to repository root at ‘/Applications/MAMP/htdocs/XXX’
    Pushing latest checkout to ‘ftp://ftp.XXX.XXX/www/’ with the given credentials
    /usr/local/bin/gitFtpPush.sh: line 17: /usr/local/bin/git-ftp: is a directory
    Completed successfully

    The files are not updated at all…
    It seems to not work.
    I think I’m really too bad for all this GIT stuffs 😀

    Have you already seen that kind of issue ?

    • eppz

      This is not GIT stuff actually, this is a third party module.
      I can’t see error message in what you posted above.
      If your path were wrong, git-ftp would tell you something about it.

      Is there any files/changes committed anyway?
      Seems there is nothing to push.

  • Pingback: xCode color scheme with a sense | eppz!()

  • Forrest

    I think I am having issues with the correct formatting of the parameters

    I am having the following error (edited for security)
    git ftp://ftp.mysite.com $PATH username mypassword public_html
    launch path not accessible
    Completed with errors, see above

    What is the correct parameter formatting no extra characters?

    $REPO ftp://ftp.mysite.com $PATH username mypassword public_html
    $REPO ftp://ftp.mysite.com $PATH
    $REPO ftp://ftp.mysite.com $PATH (username) (mypassword) (public_html)

    • eppz

      Have you made the scripts accessible?

      chmod +x /usr/local/bin/gitFtpInit.sh
      chmod +x /usr/local/bin/gitFtpPush.sh
    • eppz

      Correct formatting is:

      $PATH username mypassword ftp://mysite.com/directory/where/files/are/to/go
  • I’ve also written a little PHP script that that does deployments through FTP. It si called PHPloy and is tightly-coupled with Git to determine what which files where edited/added/deleted and uploads them accordingly. You put your FTP details in a deploy.ini file and run just a command to deploy:


    You can also deploy to multiple servers at once. And if you have multiple servers configured, you can select to deploy to one of them like this:

    phploy --server staging

    There is more that can be done – check it out on Github: https://github.com/banago/PHPloy

  • Mathieu

    Great tutorial…

    I have and error Remote host not set.
    Do you have any idea where can be the issue.


  • Nice Tutorial,
    But I am faciing the following issue, I am trying to run the first script in Custom Action and the following message appears:
    “/usr/local/bin/git-ftp: line 411: /usr/bin/curl: Argument list too long
    fatal: Could not upload files., exiting..

    Could you help me?

  • Carisa

    Hi, I’m having a little trouble getting this set up. I’m running the custom action through SourceTree with the gitFtpInit.sh file right now.

    When I run it with $REPO as the parameter I’m getting this

    git /Users/Carisa/Documents/sublime/portfolio USERNAME PASSWORD FTPPATH
    fatal: Could not upload files., exiting…
    Switching directory to repository root at ‘/Users/Carisa/Documents/sublime/portfolio’
    Pushing latest checkout to ‘FTP PATH’ with the given credentials
    There are 1254 files to sync:
    [1 of 1254] Buffered for upload ‘404.html’.
    [2 of 1254] Buffered for upload ‘CHANGELOG.md’.
    ###and on with buffering…
    Uploading …
    Completed successfully

    but nothing is showing up on the webpage. is that fatal on the second line causing the trouble?

  • Thanks for saving my fingers from Terminal hell! El Capitan clears the Bash history so I couldn’t up key to previous commits anymore. This is a dream. Cheers.

  • John LaCroix

    this works great but I noticed it didn’t remove files when I removed them from the git repo. Is there a fix for that?

  • John LaCroix

    Forget what I just said, I didn’t change to gitFtpPush.sh. Now it removes the file. AWESOME!

  • Hi all,

    I’m getting an error:

    Couldn’t posix_spawn: error 8

    When trying to either Init or Push using the scripts. Anyone seen this or know how to fix?


  • Luccas Maso

    @eppz-9aece5bee4c56e1bdae2e4dfc82cc377:disqus Same here…

  • Jmac

    Hi! As a web developer myself i created GitFTP-Deploy to satisfy my own itch. It does this with less setup. Feel free to try it out. https://eastwest.se/apps/gitftpdeploy

  • Dominic Jones

    I can’t seem to get this working in Windows. The issue seems to arise from the invocation of git-ftp from the bash or shell scripts. When running the custom action it can’t seem to process git-ftp as a command to execute despite trying various methods. Any ideas?

  • munkiwarra

    Hi there, nice work!

    Is there any way to use the git ftp config files for each project?
    What I would like is one custom action for every project, not a single one for each project.
    Otherwise I would have to create a single shortcut for every project.

    i would just need the script to run after the path has changed (which sourcetree does automatically)