Heroku

21 May 2017

  • heroku
DESCRIPTION: A collection of useful Heroku deployment tips.

Creating a Heroku remote

Using the Heroku CLI (command-line-interface), you would do $ heroku create. This will create a Heroku app with a name like sandcastle-18643. You can check the name of the app by doing git remote -v, and you should see the 2x URLs of your git repo, and the 2x Heroku URLs.

Deploying a subdirectory of a master git repository to heroku

I found myself doing a project where I had a master git repository, with multiple subdirectory projects. I only wanted to deploy a single subdirectory project to Heroku, rather than the entire master repository. In Heroku for the deployment commands to work you must be in the root of the git repository, and then it commits the entire repository.

To deploy a subdirectory, git has a special command to commit a subtree.

$ git subtree push --prefix project_name heroku master

If the below directory structure was your project with 3x subdirectories, and you only wanted to commit ReactWeather, you would do the command $ git subtree push --prefix ReactWeather heroku master

.
|-- ReactWeather
|-- ReactTimer
|-- Profile

If you want to commit to multiple subdirectory Heroku apps, then you can set up specific Heroku deploy commands.

By default when you create a Heroku remote, when deploying you would do $ git push heroku master.

The heroku bit of this command deploys to a specific url. You can see this url by typing in the terminal $ git remote -v, and you will see the url’s specific to Heroku.

If you want to set up a specific deploy command rather than the default heroku to a specific Heroku app for your subtree, then you can do:

$ heroku git:remote -a sandcastle-18643 -r SandCastle

If you then do $ git remote -v you will see the remote SandCastle there with the url to that project.

If I then wanted to deploy the ReactWeather subdirectory application to this SandCastle Heroku remote, I would run the command:

$ heroku subtree push --prefix ReactWeather SandCastle master to deploy the master branch.

Renaming Heroku branch once created

If you’ve already got a Heroku repository for SandCastle, and you want to create a new Heroku app, this is the way I have done it.

$ heroku create => to create a new Heroku app remote url, with the command name of heroku in the terminal, which you can see with git remote -v. In doing so you can see the remote url of the new Heroku app. Lets say its named beachtime-124124

Your git repo now has two subdirectory Heroku apps deployed, ReactWeather in Heroku remote SandCastle, and ReactTimer in Heroku remote BeachTime.

Open Heroku remote

The standard command to open a Heroku remote is $ heroku open. To open a remote heroku app that you previously named BeachTime, you run the command $ heroku open --remote BeachTime. And hey presto it will open in your browser.

Deleting a Heroku remote

If you wish to delete a remote from your project repo, run the command:

$ git remote rm heroku