Saturday, January 17, 2009

git project deployment with capistrano

I just sent a patch to the capistrano mailing list to update the git scm class to perform true exports using git archive rather than cloning the whole repository and then removing the git files after checkout. The main advantage of this is the elimination of the unnecessary transfer of all those git objects. However, an added feature is that git archive allows exporting specific paths from the repository, which appears to be a feature requested from time to time. With the above patch, one can configure capistrano like this:

set :scm, :git # of course
set :deploy_via, :export
set :project, [insert-your-repo-subdir-here]

Which will cause capistrano to execute something along the lines of

git archive --format=tar --remote=[your-repo-path] \

to deploy your application, cool huh? The catch, well, not all repositories (notably github) support the archive command via the git protocol, but if you're hosting your own repository or connecting by ssh, this will work just fine.


Anonymous said...

Fantastic! It works!

Unknown said...

For new readers: The patch have been accepted in capistrano ticket 65.


Lynx said...

The patch has not been accepted! The ticket has been closed with a message about this option being in the pipeline....

Lynx said...

(add to previous post)
Not only is the patch not accepted, it is not valid anymore because the codebase has changed...

Lynx said...

hm, sorry it is valid and working after all, my bad. Thanks for making it available.

Please remove my post #2 and #3 (this post) from the thread... :-)

Saima said...

I wanted to use this patch for my capistrano. From where should I get it?


crdlo said...

You can find the patch on the capistrano mailing list (

I'm in the habit of patching the git recipe in a local directory and redirecting capistrano to find it like so:


With the patched recipe file is: