Preparing your App - Git Tracked Project

In this step, you will prepare a simple project repository with GitHub that can be deployed to Heroku.

To work with Heroku, we’ll need to create a fresh application directory (remember every project should have it’s own directory.) And we’ll need to add this application to a git repository that we can use to push our application to the Heroku server.

Prepare the app - add it to Git

In order to deploy your application, we need to be able to track versions. Why? This makes sure that the current and correct version of the code is deployed to the server but also gives you the ability to rollback changes if ever anything should go wrong.

Create a New Repo

  1. First, we need to create a tracked Git repository on our local computer. To do this, open Github Desktop, and click the File Menu and the option for New Repository. Browse to the location where you want to store your project and name the folder appropriately. (Tip: you’ll probably want to store all your webapps in one place). Give the folder a good memorable and descriptive name without spaces (underscores and hypens are A.O.K.). (Tip: renaming a repo is a little messy so try to give your folder a good name up front.)

  2. This has created a Git-tracked project, we just need all our project assets to live in this folder. Copy over any basic project files you’ll need for your project (e.g. a Gemfile, an app.rb, etc. etc. ). Don’t forget to clean them up (Tip: If you’re copying from an existing project clean out any migrations, schemas in your db folder; open your Gemfile and remove all but the basic required gems, and only leave a root/main endpoint in your project!) You should have at minimum a Gemfile and a app.rb

    ProTip: Don’t forget to bundle install to add the required files to your project. And test that it runs without any errors before proceeding!

Git Initial Commit

  1. Once your files are added you’ll see something like the above which shows the inital files added to the directory. Now make an initial commit. In the bottom of half of the screen you’ll see a text entry field. Type a name like ‘initial commit’ into it and press the ‘commit to master’ button below it. Tip every commit must have a descriptive label. Get in the habit of giving your commits useful labels like “added features x,y,z to my project” or “added new endpoint”. Tip You should make regular commits for significant changes as you go.

Git Initial Commit

  1. You should see something like the above. All of the files you added are bundled up into a single commit to the repository. Let’s make the repo live. Push the Publish button on the top right. This will sync the repo with Github.com

  2. This will ask you to add a little basic information to your account. There’s also the option to keep the repo private. If you choose public, your project, it’s history and any changes will be publicly visible to any one who visits your github user page. Tip: You get a free educational discount on GitHub. It’s quick and easy to apply for and this gives you a basic plan for Zero Dollars. With that, you get unlimited free private repositories.

  3. Push publish. Give it a minute and visit your account on Github.com and you’ll see your new repository listed.

Great. You now have a functioning git repository that contains a simple application.

We need to start to add a few things to get it working with Heroku

One More Thing

We’ve essentially created a new Ruby project folder.

You’ll need to install the gems. Use bundle install to do this in the command line. Test your project by starting it with ruby app.rb and make sure everything works.

Once you’ve made these changes: do another git commit and sync the changes to github.com

×

Subscribe

The latest tutorials sent straight to your inbox.