git: fatal: Could not read from remote repository

2019-01-01 17:01发布

I am trying to set git up with http://danielmiessler.com/study/git/#website to manage my site.

I have gotten to the last step in the instructions: git push website +master:refs/heads/master

I am working using the git ming32 command line in win7

$ git push website +master:refs/heads/master
Bill@***.com's password:
Connection closed by 198.91.80.3
fatal: Could not read from remote repository.

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

One problem here may be that the program is looking for Bill@***.com. when I connect via ssh to my site I have a different username( lets say 'abc'). so maybe this should be abc@***.com. If so I don't know how to change this or if I can push under an alias

标签: git
30条回答
萌妹纸的霸气范
2楼-- · 2019-01-01 17:29

I had the same error, which brought me to this answer that didn't help me. I was trying to create a new "bare" repository for the first time using the commands below to track to an NTFS location:

cd myrepository
git init --bare \\myserver.mycompany.local\myrepository.git
git init
git status
git add .
git status
git commit -m "Initial Commit"
git remote add origin \\myserver.mycompany.local\myrepository.git
git push -u origin master
git status

My problem turned out to be using the back slashes instead of forward slashes in the NTFS location when trying to add origin to set the (new) tracked upstream branch.

I had to remove the origin using:

git remote rm origin

Then add the origin again using the expected forward slashes

git remote add origin //myserver.mycompany.local/myrepository.git

Hope this helps someone in the future.

查看更多
低头抚发
3楼-- · 2019-01-01 17:30

I was facing same issue a while ago...

my .git/config had

url = git@github.com:manishnakar/polymer-demo.git

I replaced it with

url = https://github.com/manishnakar/polymer-demo.git 

and it works now:)

查看更多
永恒的永恒
4楼-- · 2019-01-01 17:32

In your .git/config file

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

And simply

git push YOUR_APP_NAME master:master 
查看更多
梦醉为红颜
5楼-- · 2019-01-01 17:33

Make sure you have correct url in .git/config

url = git@github.com:username/repo.git

If it's your first push, you'll need to set up correct upstream

$ git push -u origin master

You can check which key is used by:

$ ssh -vvv git@github.com

The reply should contain something like this:

debug1: Next authentication method: publickey
debug1: Offering RSA public key: ~/.ssh/id_rsa
...
You've successfully authenticated, but GitHub does not provide shell access.

Also it's possible to define rules for ssh in ~/.ssh/config, e.g. based on aliases:

   Host github
      HostName github.com 
      User git
      IdentityFile "~/.ssh/id_rsa"

   Host git
      HostName github.com 
      User git
      IdentityFile "~/.ssh/some_other_id"

You can set connect to different ports, use different username etc. for each alias.

查看更多
几人难应
6楼-- · 2019-01-01 17:33

Your ssh key most likely had been removed from ssh agent

ssh-add ~/.ssh/id_rsa

where id_rsa is a ssh key associated with git repo

查看更多
回忆,回不去的记忆
7楼-- · 2019-01-01 17:33

For my case, I am using Corporate network (without internet connection) in office. In order to pull code from github, I set https proxy in gitbash and then use https instead of ssh to pull code,it works fine. However when comes to push code, the https proxy won't work. So either switch to Internet network (with internet connection) or set ssh proxy can solve the problem.

查看更多
登录 后发表回答