<p>My master branch layout is like this:</p>

<p><strong>/</strong> &lt;-- top level</p>

<p><strong>/client</strong> &lt;-- desktop client source files</p>

<p><strong>/server</strong> &lt;-- Rails app</p>

<p>What I'd like to do is only pull down the /server directory in my <code>deploy.rb</code>, but I can't seem to find any way to do that. The /client directory is huge, so setting up a hook to copy /server to / won't work very well, it needs to only pull down the Rails app.</p>

[{'answer_id': 29628, 'author': 'Silas Snider', 'author_id': 2933, 'author_profile': 'https://Stackoverflow.com/users/2933', 'pm_score': 1, 'selected': False, 'text': "<p>Unfortunately, git provides no way to do this. Instead, the 'git way' is to have two repositories -- client and server, and clone the one(s) you need.</p>\n"}, {'answer_id': 34599, 'author': 'Federico Builes', 'author_id': 161, 'author_profile': 'https://Stackoverflow.com/users/161', 'pm_score': 2, 'selected': False, 'text': '<p>You can have two git repositories (client and server) and add them to a "super-project" (app). In this "super-project" you can add the two repositories as submodules (check <a href="https://git.wiki.kernel.org/articles/g/i/t/GitSubmoduleTutorial_c489.html" rel="nofollow noreferrer">this tutorial</a>).</p>\n\n<p>Another possible solution (a bit more dirty) is to have separate branches for client and server, and then you can pull from the \'server\' branch.</p>\n'}, {'answer_id': 861804, 'author': 'Simon Woodside', 'author_id': 102675, 'author_profile': 'https://Stackoverflow.com/users/102675', 'pm_score': 2, 'selected': False, 'text': '<p>There is a solution. Grab crdlo\'s <a href="http://blog.crdlo.com/2009/01/git-project-deployment-with-capistrano.html" rel="nofollow noreferrer">patch for capistrano</a> and the <a href="http://github.com/jamis/capistrano/tree/master" rel="nofollow noreferrer">capistrano source</a> from github. Remove your existing capistrano gem, appy the patch, setup.rb install, and then you can use his very simple configuration line <code>set :project, "mysubdirectory"</code> to set a subdirectory.</p>\n\n<p>The only gotcha is that apparently github doesn\'t "support the archive command" ... at least when he wrote it. I\'m using my own private git repo over svn and it works fine, I haven\'t tried it with github but I imagine if enough people complain they\'ll add that feature.</p>\n\n<p>Also see if you can get capistrano authors to add this feature into cap <a href="https://capistrano.lighthouseapp.com/projects/8716/tickets/65-git-export-should-use-archive" rel="nofollow noreferrer">at the relevant bug</a>.</p>\n'}, {'answer_id': 1434990, 'author': 'StuFF mc', 'author_id': 476068, 'author_profile': 'https://Stackoverflow.com/users/476068', 'pm_score': 0, 'selected': False, 'text': "<p>Looks like it's also not working with codebasehq.com so I ended up making capistrano tasks that cleans the mess :-) Maybe there's actually a less hacky way of doing this by overriding some capistrano tasks...</p>\n"}, {'answer_id': 2047574, 'author': 'thodg', 'author_id': 248701, 'author_profile': 'https://Stackoverflow.com/users/248701', 'pm_score': 7, 'selected': True, 'text': '<p>Without any dirty forking action but even dirtier !</p>\n\n<p>In my config/deploy.rb :</p>\n\n<pre><code>set :deploy_subdir, "project/subdir"\n</code></pre>\n\n<p>Then I added this new strategy to my Capfile :</p>\n\n<pre><code>require \'capistrano/recipes/deploy/strategy/remote_cache\'\n\nclass RemoteCacheSubdir &lt; Capistrano::Deploy::Strategy::RemoteCache\n\n  private\n\n  def repository_cache_subdir\n    if configuration[:deploy_subdir] then\n      File.join(repository_cache, configuration[:deploy_subdir])\n    else\n      repository_cache\n    end\n  end\n\n  def copy_repository_cache\n    logger.trace "copying the cached version to #{configuration[:release_path]}"\n    if copy_exclude.empty? \n      run "cp -RPp #{repository_cache_subdir} #{configuration[:release_path]} &amp;&amp; #{mark}"\n    else\n      exclusions = copy_exclude.map { |e| "--exclude=\\"#{e}\\"" }.join(\' \')\n      run "rsync -lrpt #{exclusions} #{repository_cache_subdir}/* #{configuration[:release_path]} &amp;&amp; #{mark}"\n    end\n  end\n\nend\n\n\nset :strategy, RemoteCacheSubdir.new(self)\n</code></pre>\n'}, {'answer_id': 6969505, 'author': 'Stephan Wehner', 'author_id': 447469, 'author_profile': 'https://Stackoverflow.com/users/447469', 'pm_score': 0, 'selected': False, 'text': '<p>This has been working for me for a few hours.</p>\n\n<pre><code># Capistrano assumes that the repository root is Rails.root\nnamespace :uploads do\n  # We have the Rails application in a subdirectory rails_app\n  # Capistrano doesn\'t provide an elegant way to deal with that\n  # for the git case. (For subversion it is straightforward.)\n  task :mv_rails_app_dir, :roles =&gt; :app do\n    run "mv #{release_path}/rails_app/* #{release_path}/ "\n  end\nend\n\nbefore \'deploy:finalize_update\', \'uploads:mv_rails_app_dir\'\n</code></pre>\n\n<p>You might declare a variable for the directory (here rails_app).</p>\n\n<p>Let\'s see how robust it is. Using "before" is pretty weak.</p>\n'}, {'answer_id': 8928491, 'author': 'Thomas Fankhauser', 'author_id': 408557, 'author_profile': 'https://Stackoverflow.com/users/408557', 'pm_score': 3, 'selected': False, 'text': '<p>We\'re also doing this with Capistrano by cloning down the full repository, deleting the unused files and folders and move the desired folder up the hierarchy.</p>\n\n<p>deploy.rb</p>\n\n<pre><code>set :repository,  "git@github.com:name/project.git"\nset :branch, "master"\nset :subdir, "server"\n\nafter "deploy:update_code", "deploy:checkout_subdir"\n\nnamespace :deploy do\n\n    desc "Checkout subdirectory and delete all the other stuff"\n    task :checkout_subdir do\n        run "mv #{current_release}/#{subdir}/ /tmp &amp;&amp; rm -rf #{current_release}/* &amp;&amp; mv /tmp/#{subdir}/* #{current_release}"\n    end\n\nend\n</code></pre>\n\n<p>As long as the project doesn\'t get too big this works pretty good for us, but if you can, create an own repository for each component and group them together with git submodules.</p>\n'}, {'answer_id': 21344915, 'author': 'Mr Friendly', 'author_id': 3233988, 'author_profile': 'https://Stackoverflow.com/users/3233988', 'pm_score': 5, 'selected': False, 'text': '<p>For Capistrano 3.0, I use the following:</p>\n\n<p>In my <code>Capfile</code>:</p>\n\n<pre><code># Define a new SCM strategy, so we can deploy only a subdirectory of our repo.\nmodule RemoteCacheWithProjectRootStrategy\n  def test\n    test! " [ -f #{repo_path}/HEAD ] "\n  end\n\n  def check\n    test! :git, :\'ls-remote\', repo_url\n  end\n\n  def clone\n    git :clone, \'--mirror\', repo_url, repo_path\n  end\n\n  def update\n    git :remote, :update\n  end\n\n  def release\n    git :archive, fetch(:branch), fetch(:project_root), \'| tar -x -C\', release_path, "--strip=#{fetch(:project_root).count(\'/\')+1}"\n  end\nend\n</code></pre>\n\n<p>And in my <code>deploy.rb</code>:</p>\n\n<pre><code># Set up a strategy to deploy only a project directory (not the whole repo)\nset :git_strategy, RemoteCacheWithProjectRootStrategy\nset :project_root, \'relative/path/from/your/repo\'\n</code></pre>\n\n<p>All the important code is in the strategy <code>release</code> method, which uses <code>git archive</code> to archive only a subdirectory of the repo, then uses the <code>--strip</code> argument to <code>tar</code> to extract the archive at the right level.</p>\n\n<p><strong>UPDATE</strong></p>\n\n<p>As of Capistrano 3.3.3, you can now use the <code>:repo_tree</code> configuration variable, which makes this answer obsolete. For example:</p>\n\n<pre><code>set :repo_url, \'https://example.com/your_repo.git\'\nset :repo_tree, \'relative/path/from/your/repo\' # relative path to project root in repo\n</code></pre>\n\n<p>See <a href="http://capistranorb.com/documentation/getting-started/configuration" rel="noreferrer">http://capistranorb.com/documentation/getting-started/configuration</a>.</p>\n'}, {'answer_id': 23497408, 'author': 'JAlberto', 'author_id': 2699576, 'author_profile': 'https://Stackoverflow.com/users/2699576', 'pm_score': 1, 'selected': False, 'text': '<p>I created a snipped that works with Capistrano 3.x based in previous anwers and other information found in github:</p>\n\n<pre><code># Usage: \n# 1. Drop this file into lib/capistrano/remote_cache_with_project_root_strategy.rb\n# 2. Add the following to your Capfile:\n#   require \'capistrano/git\'\n#   require \'./lib/capistrano/remote_cache_with_project_root_strategy\'\n# 3. Add the following to your config/deploy.rb\n#    set :git_strategy, RemoteCacheWithProjectRootStrategy\n#    set :project_root, \'subdir/path\'\n\n# Define a new SCM strategy, so we can deploy only a subdirectory of our repo.\nmodule RemoteCacheWithProjectRootStrategy\n  include Capistrano::Git::DefaultStrategy\n  def test\n    test! " [ -f #{repo_path}/HEAD ] "\n  end\n\n  def check\n    test! :git, :\'ls-remote -h\', repo_url\n  end\n\n  def clone\n    git :clone, \'--mirror\', repo_url, repo_path\n  end\n\n  def update\n    git :remote, :update\n  end\n\n  def release\n    git :archive, fetch(:branch), fetch(:project_root), \'| tar -x -C\', release_path, "--strip=#{fetch(:project_root).count(\'/\')+1}"\n  end\nend\n</code></pre>\n\n<p>It\'s also available as a Gist on <a href="https://gist.github.com/jalberto/0cfc86174f4f7a3307d3" rel="nofollow">Github</a>.</p>\n'}, {'answer_id': 25446122, 'author': 'fsainz', 'author_id': 499154, 'author_profile': 'https://Stackoverflow.com/users/499154', 'pm_score': 2, 'selected': False, 'text': '<p>For Capistrano 3, based on @Thomas Fankhauser answer:</p>\n\n<pre><code>set :repository,  "git@github.com:name/project.git"\nset :branch, "master"\nset :subdir, "relative_path_to_my/subdir"\n\n\nnamespace :deploy do\n\n  desc "Checkout subdirectory and delete all the other stuff"\n  task :checkout_subdir do\n\n    subdir = fetch(:subdir)\n    subdir_last_folder  = File.basename(subdir)\n    release_subdir_path = File.join(release_path, subdir)\n\n    tmp_base_folder = File.join("/tmp", "capistrano_subdir_hack")\n    tmp_destination = File.join(tmp_base_folder, subdir_last_folder)\n\n    cmd = []\n    # Settings for my-zsh\n    # cmd &lt;&lt; "unsetopt nomatch &amp;&amp; setopt rmstarsilent" \n    # create temporary folder\n    cmd &lt;&lt; "mkdir -p #{tmp_base_folder}"  \n    # delete previous temporary files                \n    cmd &lt;&lt; "rm -rf #{tmp_base_folder}/*"  \n    # move subdir contents to tmp           \n    cmd &lt;&lt; "mv #{release_subdir_path}/ #{tmp_destination}"   \n    # delete contents inside release      \n    cmd &lt;&lt; "rm -rf #{release_path}/*"   \n    # move subdir contents to release             \n    cmd &lt;&lt; "mv #{tmp_destination}/* #{release_path}" \n    cmd = cmd.join(" &amp;&amp; ")\n\n    on roles(:app) do\n      within release_path do\n        execute cmd\n      end\n    end\n  end\n\nend\n\nafter "deploy:updating", "deploy:checkout_subdir"\n</code></pre>\n'}, {'answer_id': 60118376, 'author': 'fFace', 'author_id': 2955429, 'author_profile': 'https://Stackoverflow.com/users/2955429', 'pm_score': 1, 'selected': False, 'text': '<p>dont know if anyone is still interested on this. but just letting you guys if anyone is looking for an answer.\nnow we can use: :repo_tree</p>\n\n<p><a href="https://capistranorb.com/documentation/getting-started/configuration/" rel="nofollow noreferrer">https://capistranorb.com/documentation/getting-started/configuration/</a></p>\n'}]
['https://Stackoverflow.com/questions/29168', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/574/']