26

I have a few apps on Heroku, nothing has had this problem but I suddenly have had issues running git. Now I can't deploy my app to Heroku. When I run

git push heroku master

I get the following:

fatal: unable to access 'https://git.heroku.com/<herokuappname>.git/': Could not resolve host: (nil); nodename nor servname provided, or not known

When I run

git remote -v

I get the following:

heroku  https://git.heroku.com/<herokuappname>.git (fetch)
heroku  https://git.heroku.com/<herokuappname>.git (push)

I've looked up everything. Please help, thank you.

jthedudeoflife
  • 391
  • 1
  • 4
  • 11
  • Did you checked [this thread](http://stackoverflow.com/questions/18290822/why-does-git-fetch-fail-with-could-not-resolve-host-nil-with-https-git) ? It's not heroku-related, but also has issues with not being able to connect to git repo, which seem to be root problem. – Dariusz Aniszewski Feb 21 '15 at 10:57

10 Answers10

50

Whenever this randomly happens to me, removing and adding heroku again as a remote reference always works.

First check if you do have heroku as a remote.

git remote -v

If heroku is present, remove it.

git remote rm heroku

Then add it back.

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

Usually this works with me, try it and let me know what happens.

Rachelle Uy
  • 838
  • 10
  • 15
  • 3
    Didn't work for me , heroku git:remote -a , taken from http://stackoverflow.com/questions/5129598/how-to-link-a-folder-with-an-existing-heroku-app did the job. – Ohad Dahan Sep 23 '16 at 13:30
  • Same with me I pulled a repository and I had to add: heroku keys:add first and then do heroku git:remote -a – trickydiddy Oct 26 '17 at 14:13
  • This method doesn't work on my terminal. $ git push heroku master master ssh: connect to host heroku.com port 22: Connection timed out fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. – stevezkw Apr 22 '22 at 08:02
29

Try this:

heroku keys:add

Worked for me

Sergey
  • 47,222
  • 25
  • 87
  • 129
10
git remote -v
git remote rm heroku
git remote add heroku git@heroku.com:project(full url).git
heroku keys:add

These steps worked

4

Try exiting from the terminal, start a new terminal (comand line) process and go to the appropriate directory and then try to push to heroku master once again.

I had encountered an error similar to yours :-

fatal: unable to access 'https://git.heroku.com/<herokuappname>.git/': Could not resolve host: git.heroku.com

I did the same thing as mentioned above and it worked out well for me. I am hoping that it will work for you as well.

Pavan Vasan
  • 391
  • 1
  • 9
  • 28
  • This solved my problem. I was really confused because ping and Chrome worked fine. Apparently my old terminal sessions were using a closed socket (i.e. `$SSH_AUTH_SOCK` variable had changed). – TastyWheat Feb 06 '19 at 17:34
  • @TastyWheat: If it helped, would be awesome if you could upvote my answer. Thanks. :) – Pavan Vasan Feb 12 '19 at 07:37
3

I was able to solve this issue by logging into heroku with heroku login

Steve F.
  • 71
  • 1
  • 2
1

This error make me mad ! It's happend again and again, tips above doesn't work for me. As u can see on screenshot I do nothing betwin attemps! It just work or don't, but more often don't !

SHR
  • 7,940
  • 9
  • 38
  • 57
Andrey
  • 21
  • 1
1

One of the main causes of that error is simply a bad internet connection, If you come across issues like this, simply changing your internet connection or using a better option fixes this problem.

Martins
  • 1,130
  • 10
  • 26
1

This worked for me in the following order

git remote rm heroku
heroku login
heroku git:remote -a <app_name>
git push heroku master
Syre Musk
  • 57
  • 7
0

If you have already connected any other remote from git using ssh then you have to connect heroku remote with ssh only. To check how remote connected:

git remote -v

just remove https remote of heroku, connect again with ssh remote. like:

git remote add heroku git@heroku.com:<yourProject>.git

It should work.

Mitesh Anand
  • 133
  • 1
  • 8
0

This worked for me

  1. heroku git:remote -a app-name
  2. git push heroku master