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

How can I deploy/push only a subdirectory of my git repo 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 bingit initgit add .git commit -m"deploy"git push git@heroku.com:your-project-name.git -frm -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 incd "$( dirname "$0" )"#create new git repository and add everythinggit initgit add .git commit -m"init"git remote add heroku git@heroku.com:young-rain-5086.git#pull heroku but then checkback out our current local master and mark everything as mergedgit pull heroku mastergit checkout --ours .git add -ugit commit -m"merged"#push back to heroku, open web browser, and remove git repositorygit push heroku masterheroku openrm -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!