26
nshastri@N-SHASTRI ~/datasciencecoursera (master)
$ git push origin master

ssh: Could not resolve hostname https: no address associated with name

fatal: Could not read from remote repository.

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

HeatfanJohn
  • 7,143
  • 2
  • 35
  • 41

5 Answers5

53

Simply type:

git remote -v

and double-check the url associated with origin for your upstream repo.

Once you have the right url, update your remote origin with another git remote command:

git remote set-url origin /the/right/url

In your case, the url is wrong:

https:/github.com/nkshastri/datasciencecoursera.git
# instead of:
https://github.com/nkshastri/datasciencecoursera.git
     ^^^^

Simply type:

git remote set-url origin https://nkshastri@github.com/nkshastri/datasciencecoursera

Then try again:

git push -u origin master

(with master, not maaster)

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks for help I tried doing it and still no success. I am posting a screen shot for reference. – Narendra Kumar Shastri Sep 22 '14 at 08:53
  • @NarendraKumarShastri what os and git version are you using? – VonC Sep 22 '14 at 09:05
  • My os is windows 7 Git bash version is version 1.9.4-preview20140815 – Narendra Kumar Shastri Sep 24 '14 at 05:53
  • @NarendraKumarShastri what is the output of `git remote -v` (no screenshot, just the text) – VonC Sep 24 '14 at 05:56
  • I am not able to post sceen shot so output is:nshastri@N-SHASTRI ~/datasciencecoursera (master) $ git remote -v origin https:/github.com/nkshastri/datasciencecoursera.git (fetch) origin https:/github.com/nkshastri/datasciencecoursera.git (push) – Narendra Kumar Shastri Sep 26 '14 at 07:08
  • @NarendraKumarShastri Perfect, the text output is always better than a picture. I have edited my answer, and suggested a solution. – VonC Sep 26 '14 at 07:11
  • I am not able to execute push command as I am receiving error as ssh: Could not resolve hostname https: no address associated with name fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. – Narendra Kumar Shastri Sep 26 '14 at 07:12
  • @NarendraKumarShastri if you see "https", it is not an error 'as ssh' (it has nothing to do with ssh). Simply type the `git remote set-url` I suggest in my answer, then try again. – VonC Sep 26 '14 at 07:13
  • Thanks a ton. I am able to change the origin however I am still not able to push getting following error: – Narendra Kumar Shastri Sep 29 '14 at 06:47
  • nshastri@N-SHASTRI ~/datasciencecoursera (master) $ git push -u origin master Password for 'https://nkshastri@github.com': To https://nkshastri@github.com/nkshastri/datasciencecoursera.git ! [rejected] master -> master (fetch first) error: failed to push some refs to https://nkshastri@github.com/nkshastri/datasciencecoursera.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. – Narendra Kumar Shastri Sep 29 '14 at 06:49
  • This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. – Narendra Kumar Shastri Sep 29 '14 at 06:49
  • @NarendraKumarShastri sure, do a `git pull --rebase` first. Then push. – VonC Sep 29 '14 at 06:54
  • @NarendraKumarShastri see more at https://www.atlassian.com/git/tutorials/syncing/git-pull/#pulling-via. The other option would be to make sure you create an **empty** repo on GitHub – VonC Sep 29 '14 at 07:04
  • Getting following error: failed to push some refs to 'https://nkshastri@github.com/nkshastri/datasciencecoursera.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. – Narendra Kumar Shastri Dec 02 '14 at 09:18
  • @NarendraKumarShastri that seems to be an entirely **unrelated** question. Please make it an independent question, and accept the current answer for the current question (the one at the top of the page, the one you initially asked) – VonC Dec 02 '14 at 09:20
  • Sorry for the confusion. I am able to sync and push my work to repo. Thanks for all your support. I accept the answer for current question. No more issues. Thanks once again. – Narendra Kumar Shastri Dec 03 '14 at 11:30
15

Sometimes this can be caused by a network issue. Try restarting your wifi or, if the repository is behind a VPN, make sure you are on the VPN.

Tom Howard
  • 4,672
  • 2
  • 43
  • 48
vancexu
  • 1,548
  • 3
  • 19
  • 30
0

You are probably trying to connect a FALSE NAME DIR your repository name should be the SAME as your folder name in local environment.

git repo: gitRepo folder name: gitRepo now you can push

it is also a good practice to first CLONE your new repository to a different folder and then you can COPY your code to this new folder and then change its name to the right git repository name.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
noririco
  • 765
  • 6
  • 15
0

For me in ~/.git-credentials I have two credential is has been stored. So I keep one that I want to interact now push, pull working fine.

For more information about git-credentials follow this link

Arul
  • 1,031
  • 13
  • 23
0

This solution is applicable only for small projects...

To get around this... I created a new directory with files having the same name as in the old directory.

Simply copy-pasted the code from old files to the corresponding files of the new directory...

Then did the usual command chain...

git remote add URL_OF_YOUR_REPO
git branch -M main
git status
git add .
git commit -m "Problem Solved!"
git push -u origin main

Didn't face any error after this. Useful for small repos.

Karthik
  • 33
  • 8