Integrating Heroku with GitHub: Project Structure Tips

I’m developing a web service and would like to manage the source code on GitHub while hosting the app on Heroku. I haven’t found a specific guide for my case, so I’m reaching out here for advice.

I aim to have this directory layout:

/project
  .git
  README <-- main project readme
  TODO.otl <-- project outline
  ... <-- other relevant files
  /my_rails_app
     app
     config
     ...
     README <-- rails readme

In this setup, ‘project’ aligns with my GitHub repository at http://github.com/myuser/project, and ‘my_rails_app’ contains the code for deployment on Heroku. Do I need a distinct branch for the Rails app, or is there a more straightforward way to address this?

I suppose I could store the non-Rails project files in ‘my_rails_app’, but it feels odd to overwrite the existing Rails README. Leaving it there would result in the GitHub page showing the Rails README, which wouldn’t make sense.

I attempted to deploy using this setup and ran:

git push heroku

from the main project directory, but Heroku didn’t recognize my intention to deploy from the subfolder:

-----> Heroku receiving push
 !     Heroku push rejected, no Rails or Rack app detected.

I hit the same issue with a monorepo setup. Git subtree works, but here’s what I found easier: Heroku actually supports monorepos natively. Just create a heroku.yml file in your root and set the setup path to your Rails directory - tells Heroku exactly where your app lives. No separate pushes needed. Even simpler? Connect your GitHub repo through Heroku’s dashboard and specify which subdirectory has your Rails app. Then you get automatic deploys from GitHub while keeping your project structure intact.

i also had some success with heroku’s buildpack options. you can set up a custom buildpack for those subfolders or try using the APP_BASE env var with specific buildpacks. but honestly, stick with the git subtree method – it’s what most devs resort to for cases like this.

Had this exact problem with my first Rails deployment on Heroku. Heroku wants your app files in the root directory, not buried in a subfolder. I’ve found two ways to handle this. The easiest fix is using git subtree to push just your Rails directory. Run git subtree push --prefix my_rails_app heroku main from your main project folder. This pushes only what’s inside my_rails_app to Heroku like it’s the root directory, so Heroku can detect and deploy it properly. You could also split things into separate repos - one for project docs, another for the Rails app. Cleaner but means juggling two repos. I stick with subtree since it’s worked great across multiple projects without any branch headaches.