Select Page

Introduction

 Heroku is a platform for developers which allows them to create, run and operate programs all within the Cloud. It is also known as a polyglot platform, due to the fact that it allows the deployment of applications that are written in any programming language. One of its greatest features is the integration with GitHub, being the primary reason why so many developers adorn Heroku. 

You can deploy code from within a GitHub repository directly to the heroku web app, which means that you get all of the goodness of git, along with the reliability of Heroku. But wait. There’s a problem.

It seems that some of the users are facing issues to push their code from their GitHub repository to the heroku app, with an error message that states:

fatal: ‘heroku’ does not appear to be a git repository

If this is exactly the same situation you’re facing, we have your fix right here. What you should know is that you’re missing out on something! 


Why does Heroku not appear to be a git repository?

The main reason as to why you may not be able to push code to Heroku is because you’re missing out on the git remote. Git remote is a command which allows you to create connections to a remote repository. Heroku uses its own remote for your code to be pushed. But before you can push any code, you need to ensure that your repository is linked to the Heroku remote. 

The next section will visualize the whole process of setting up a link with the Heroku remote, from the ground up to help you better understand where you might be doing wrong, and what you may be missing out on. 


Fix ‘heroku’ does not appear to be a git repository

Login to heroku

The first thing you should ensure is that you’re logged into Heroku from the command line. This is a common reason as to why some users may be unable to push code. To login to the heroku CLI program, use the following command:

$ heroku login

This command will take you to the login page in your default Web Browser. If you don’t want that and would like to enter the credentials directly from your terminal, you’d want to use:

$ heroku login -i

Initialize git

We’re not logged into heroku CLI now. The next few steps nay not be that important, and you probably already have these done yourself. But just for clarity, let me show you a basic setup process. 

The first thing you probably do when starting out on a project is initialize a folder, fair basics. So let me do that, by executing:

$ git init

Inside the folder where I’d like for my program’s code to be stored. 

Create a commit

Let’s create a commit to make the process fair. You’d probably not want to publish a project that doesn’t even have a text file, will ya?!

# Create a new file and append some text
$ touch demo.txt
$ echo “Hello World!” > demo.txt

# Stage and commit the file
$ git add demo.txt
$ git commit -m “A Hello World text is created!”

Aa-ha! Very, very, basic. Doesn’t matter. Because the next 3 sections are what you’re like to put your heaviest attention on! So get your eyes wide open and don’t fall asleep, you night owl!

Initialize the heroku app

The next part is to declare or initialize your git repository folder as a heroku app. To do this, execute the following command from inside the folder of your local git repository:

$ heroku create <app_name>

Replace the <app_name> with the name you’d like to give to your app. Don’t just give anything random and keep in mind about the end product you’re aiming to create!

Add git remote for the app

Yes, comrades. It is the moment of truth – the part where most people actually get stuck and miss out on. What people tend to confuse is that initializing the heroku app with “heroku create” alone will not get your job done. before you can push code to heroku, you actually need to set up git remote. Simply do that by using the following command in your terminal, and make sure that you’re on the folder of your repository:

$ heroku git:remote -a <app_name>

Replace the <app_name> with the name of your app you used to initialize your folder with heroku create. Don’t end up giving a new name to this, as you’d probably find yourself stuck in a messed up situation!

Push the code to heroku

Last but not least, you can now push your app directly to heroku, given that you had properly followed all the previous steps. Use the following command in your terminal:

$ git push heroku master

Wala! You should now be able to push code to heroku from your git repository without any further issues. If you still encountering more trouble and none of the above had helped, your last resort would be to:

  • Check your internet connection

Just kidding! It wouldn’t help…