296

When I try to push my app to Heroku I get this response:

fatal: 'heroku' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I have tried 'heroku keys:add' but still comes up with the same result. I already have an ssh key for my GitHub account.

Tim
  • 3,191
  • 2
  • 16
  • 22

25 Answers25

654

To add a Heroku app as a Git remote, you need to execute heroku git:remote -a yourapp.

Source: Deploying with Git

  • 13
    This is the solution if you cloned the repo. – JGallardo Sep 24 '13 at 06:01
  • 3
    After adding a valid remote, notice that `git push heroku master` will fail if you are trying to deploy from a subdirectory. The deploy with heroku must be done from root directory with a valid package.json and .git folder, as told here https://stackoverflow.com/questions/38658038/why-does-heroku-fail-to-detect-node-js-buildpack – Junior Mayhé Jul 31 '17 at 17:56
  • 10
    I'd add that by `yourapp` you mean the name of the heroku app, which might not always match the name of your app in git or locally, etc. – Lee McAlilly May 14 '19 at 22:05
  • This was the solution and I did not clone the repo, thank you! – lizziepika Nov 19 '20 at 21:28
  • 2
    This error occurs due to no mapping/linking between local repo and heroku repo. To make a link run this command `heroku git:remote -a yourAppName`. youAppName should be your app name in the heroku. – chanduthedev Sep 24 '21 at 09:25
  • Worked for me, I had to reinstall heroku on my pc and this was required to fix the link again. – Nick the Community Scientist Nov 24 '21 at 22:57
  • If this doesn't work, check `.git/config` for the Heroku remote entry. It should have two lines, one that specifies `url` and one for `fetch`. If you don't have both entries, delete the Heroku entry in `.git/config` and run `heroku git:remote -a yourapp` again. – wbharding Apr 14 '22 at 14:34
  • revisiting this after 4 years, `yourapp` is the app name and not the git url from heroku (just a reminder) – Gel Jul 03 '22 at 11:00
74

You could try the following in your root directory:

// initialize git for your project, add the changes and perform a commit

git init
git add .
git commit -m "first commit"

// create heroku app and push to heroku

heroku create
git push heroku master

Not sure where you are in the process. You also don't need github to deploy on heroku, just git. Hope this helps!

StickMaNX
  • 1,982
  • 2
  • 16
  • 13
60

First, make sure you're logged into heroku:

heroku login 

Enter your credentials.

It's common to get this error when using a cloned git repo onto a new machine. Even if your heroku credentials are already on the machine, there is no link between the cloned repo and heroku locally yet. To do this, cd into the root dir of the cloned repo and run

heroku git:remote -a yourapp
mepler
  • 907
  • 8
  • 12
19

Following official Heroku article:

Initialize GIT

$ cd myapp
$ git init

$ git add .
$ git commit -m "my first commit"

Then create (initialize) heroku app with:

$ heroku create YourAppName

Lastly add git remote:

$ heroku git:remote -a YourAppName

Now you can safely deploy your app with:

$ git push heroku master

You should wait for some time and see if you don't get any error/interrupt on console while deploying. For details look at heroku article.

RegarBoy
  • 3,228
  • 1
  • 23
  • 44
18

heroku git:remote -a YourAppName

Fahd Mannaa
  • 295
  • 2
  • 7
  • Seems identical to existing answers but without any context. Consider upvoting those instead of adding a me-too answer. – ggorlen Sep 18 '22 at 23:03
17

You forgot to link your app name to your heroku. It's a very common mistake. if your app is not created, then use:

heroku create (optional app name)

else:

git add .
git commit -m "heroku commit"

heroku git:remote -a YOUR_APP_NAME

git push heroku master
m02ph3u5
  • 3,022
  • 7
  • 38
  • 51
12

Follow this steps:

$ heroku login

Create a new Git repository
Initialize a git repository in a new or existing directory

$ cd my-project/
$ git init
$ heroku git:remote -a appname

Deploy your application
Commit your code to the repository and deploy it to Heroku using Git.

$ git add . 
$ git commit -am "make it better"
$ git push heroku master

Existing Git repository
For existing repositories, simply add the heroku remote

$ heroku git:remote -a appname
MD Shahrouq
  • 609
  • 8
  • 16
  • Error: ---> App not compatible with buildpack: `https://codon-buildpacks.s3.amazonaws.com/buildpacks/heroku/python.tgz` ... i no understand, Where is it wrong? – KingRider Sep 15 '17 at 19:56
  • @KingRider Check which app you are deploying. IF you deploying python app , there is no need to specify Python in Requirement.txt file – MD Shahrouq Sep 28 '17 at 05:49
4

Might be worth checking the config file in the .git folder. If the heroku parameters are missing then you´ll get this error heroku param

[remote "heroku"]
    url = git@heroku.com:`[Your heroku app].git
    fetch = +refs/heads/*:refs/remotes/heroku/*

the .git folder should be in the local computer file directory for the app you created in heroku. e.g C:\Users\You\Your app.git

Hope this helps

ScottJShea
  • 7,041
  • 11
  • 44
  • 67
Beauson45
  • 41
  • 1
4

My problem was that I used git (instead of heroku git) to clone the app. Then I had to:

git remote add heroku git@heroku.com:MyApp.git

Remember to change MyApp to your app name.

Then I could proceed:

git push heroku master
douglaslps
  • 8,068
  • 2
  • 35
  • 54
4

If this error pops up, its because there is no remote named Heroku. When you do a Heroku create, if the git remote doesn’t already exist, we automatically create one (assuming you are in a git repo). To view your remotes type in:

git remote -v”. # For an app called ‘appname’ you will see the following:

$ git remote -v
heroku git@heroku.com:appname.git (fetch)
heroku git@heroku.com:appname.git (push)

If you see a remote for your app, you can just “git push master” and replace with the actual remote name.

If it’s missing, you can add the remote with the following command:

git remote add heroku git@heroku.com:appname.git

If you’ve already added a remote called Heroku, you may get an error like this:

fatal: remote heroku already exists.

so, then remove the existing remote and add it again with the above command:

git remote rm heroku

Hope this helps…

A.K.
  • 2,284
  • 3
  • 26
  • 35
3

show all apps heroku have access with

heroku apps

And check you app exist then

 execute heroku git:remote -a yourapp_exist
Beowulfdgo
  • 141
  • 1
  • 1
  • 9
2

For me the answer was to cd into the root directory of the app before running heroku create or git push heroku master

j8d
  • 446
  • 7
  • 23
2

Type heroku create then git push heroku master (this is after creating a repository with 'git init' and committing the project)

AfriPwincess
  • 123
  • 1
  • 6
1

I encountered the same error making a much more novice mistake: I was typing in Heroku with a capital "H," instead of lowercase.

I recognize that's certainly not the solution for everyone who encounters this error, but it was in my case.

1

I got the same error and it turned out I was in the wrong directory. It's a simple mistake to make so double check that you are in the root and then run heroku create and heroku git push master again. Of course you must have done git init, as mentioned in StickMaNX answer above, already before the heroku steps.

mikeym
  • 5,705
  • 8
  • 42
  • 62
1

Run this

heroku create

before pushing your code.

niranjanbajgai
  • 295
  • 1
  • 3
  • 8
1

I had the same issue, but later I found out that I forgot to create an app before deploying it. Try the following steps in terminal.

heroku login
heroku create

I am just learning heroku and often forget the steps so I wrote an article about it. You can find it here: https://medium.com/@saurav.panthee/deploy-flask-app-to-heroku-under-3-minutes-2ec1c0bc403a

Saurav Panthee
  • 589
  • 5
  • 8
1

I've seen all the answers here and the only thing missing is after going through these steps:

$ git add .
$ git commit -m "first heroku commit"

You should run the command below:

$ heroku git:remote -a <YourAppNameOnHeroku>

And lastly, run this:

$ git push -f heroku <NameOfBranch>:master

Notice I used <NameOfBranch> because if you're currently in a different branch to master it would still throw errors, so If you are working in master use master, else put the name of the branch there.

Kingston Fortune
  • 905
  • 8
  • 17
1

On the site:

https://dashboard.heroku.com/apps/**<YourAppNameOnHeroku>**/deploy/heroku-git

steps are described.

  • 2
    Welcome to Stack Overflow. [Link-only answers are discouraged here](https://meta.stackexchange.com/a/8259/248627) as they low-effort and low-value. They are also subject to "link rot", often becoming useless as links break in the future. Please edit your answer and include the main points directly in your question. See [answer]. – ChrisGPT was on strike Sep 26 '21 at 20:41
0

For those who are trying to get heroku to work on codeanywhere IDE:

heroku login
git remote add heroku git@heroku.com:MyApp.git
git push heroku
Timmy Von Heiss
  • 2,160
  • 17
  • 39
0

I had to run the Windows Command Prompt with Administrator privileges

  • Thanks for your answer. Perhaps you could explain to the OP how this is done? It always helps, also for future viewers of this thread, to give answers as detailed as possible. – niels Jan 26 '17 at 11:11
  • @niels just find the cmd icon, through the start menu for instance. Then right click and press Run as Administrator – Jesus Rodriguez Feb 01 '17 at 12:04
0

The following commands will work well for ruby on rails application deployment on heroku if heroku is already installed on developers machine. # indicates a comment

  1. heroku login
  2. heroku create
  3. heroku keys:add #this adds local machines keys to heroku so as to avoid repeated password entry
  4. git push heroku master
  5. heroku rename new-application-name #rename application to the preferred name other than the auto generated heroku name
Hamfri
  • 1,979
  • 24
  • 28
0

In my case, I was already logged-in and I just executed git push.

Nazar Medeiros
  • 437
  • 4
  • 10
0

i forgot to create a domain name before running git push heroku main. Creating a domain name resolved the problem.

Jared Forth
  • 1,577
  • 6
  • 17
  • 32
Bello Victor
  • 19
  • 1
  • 6
0

First you have to install Heroku for CLI to be recognized

npm install -g heroku

npm command requires installation of node.js

Here you may download node.js: https://nodejs.org/en/download/

Then you have to login for authentication

heroku login

If you don't have an existing heroku repo

heroku create

Otherwise if you have an existing heroku repo

git remote add heroku git@heroku.com:<your app>.git

Then you may proceed pushing

git push heroku main
Two
  • 512
  • 4
  • 17