How can I deploy/push only a subdirectory of my git repo to Heroku?

I have a project that uses Serve and is version controlled using Git. Serve creates an output folder with static files that I want to deploy to Heroku.

I don't want to deploy the Serve project itself since the Heroku Cedar stack doesn't seem too fond of it, but most importantly I want to take advantage of Heroku's great support for static websites.

Is there a way to deploy a subfolder to a git remote? Should I create a Git repo in the output folder (that sounds wrong) and push that to Heroku?


There's an even easier way via git-subtree. Assuming you want to push your folder 'output' as the root to Heroku, you can do:

git subtree push --prefix output heroku master

It appears currently that git-subtree is being included into git-core, but I don't know if that version of git-core has been released yet.


I started with what John Berryman put, but actually it can be simpler if you don't care at all about the heroku git history.

cd bin
git init
git add .
git commit -m"deploy"
git push [email protected]:your-project-name.git -f
rm -fr .git

I guess official git subtree is the best answer, but i had issue getting subtree to work on my mac.


I had a similar issue. In my case it was never a problem to blow away everything in the heroku repository and replace it with whatever is in my subdirectory. If this is your case you can use the following bash script. Just put it in your Rails app directory.

#!/bin/bash

#change to whichever directory this lives in
cd "$( dirname "$0" )"

#create new git repository and add everything
git init
git add .
git commit -m"init"
git remote add heroku [email protected]:young-rain-5086.git

#pull heroku but then checkback out our current local master and mark everything as merged
git pull heroku master
git checkout --ours .
git add -u
git commit -m"merged"

#push back to heroku, open web browser, and remove git repository
git push heroku master
heroku open
rm -fr .git

#go back to wherever we started.
cd -

I'm sure there are plenty of ways to improve upon this - so feel free to tell me how!