Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I push a part of my git repo to Heroku?

Tags:

git

heroku

I have a multi-module app that is already on Github. It is comprised of two modules, one of them an Android app and the other a Rails based Web app. So my project's directory structure is in the form of:

ProjectRoot
|
+-- web
|
+-- android
|
+-- .git

As such I cannot simply cd into ProjectRoot and push my app to Heroku as the root folder of the Rails app is ProjectRoot/web. Is there a way to push the web folder to Heroku? If I turn web into a git sub module, it should be easy to accomplish this, but then I only have 5 private repos on Git and I prefer to consume only 1 repo for my whole app.

like image 977
Behrang Avatar asked May 12 '11 11:05

Behrang


People also ask

How do I push a specific folder to Heroku?

You can use git subtree push . It will generate a new commit tree with your directory as root, and push it. Full documentation is here. This works great.

How do I push to a specific repo in git?

To push the commit from the local repo to your remote repositories, run git push -u remote-name branch-name where remote-name is the nickname the local repo uses for the remote repositories and branch-name is the name of the branch to push to the repository. You only have to use the -u option the first time you push.

How do I import from GitHub to Heroku?

Open Deploy tab and scroll to the “Deployment method” section. Select GitHub as the method. It will show a “Connect to GitHub” option where we can provide our GitHub repository. If you are doing it for the first time, Heroku will ask permission to access your GitHub account.


3 Answers

You can use git subtree push. It will generate a new commit tree with your directory as root, and push it.

git subtree push --prefix web heroku master

Full documentation is here.

like image 91
Michaël Witrant Avatar answered Oct 12 '22 14:10

Michaël Witrant


The git subtree command (built in, now) is a good way to do this. If you want to push a subtree of a branch to become your master, you can use something like:

git push --force heroku `git subtree split --prefix web HEAD`:master

like image 44
brookr Avatar answered Oct 12 '22 15:10

brookr


You could also use git branches instead of subfolders. If you have git 1.7.2 or newer, you can simply do git checkout --orphan android to create a branch that is disconnected from your master branch (assumed here to be the web folder). Once you have checked out the orphan branch, run git rm -rf . to remove existing files before copying in your android-specific files to the now empty root directory.

If you want to use separate folders for each module, you can clone the repository twice and use this structure:

ProjectRoot
├── android
│   └── .git
└── web
    └── .git
like image 30
bmaland Avatar answered Oct 12 '22 14:10

bmaland