我试图设置git与http://danielmiessler.com/study/git/#website来管理我的网站。

我已经到了指令的最后一步:git push website +master:refs/heads/master

我正在win7中使用git ming32命令行工作

$ 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.

这里的一个问题可能是程序正在寻找bill@* **.com。当我通过ssh连接到我的网站,我有一个不同的用户名(让我们说'abc')。也许这个应该是abc@***。com。如果是这样,我不知道如何改变这一点,或者如果我可以推下一个别名


当前回答

我之前也遇到过同样的问题…

我的.git/config有

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

我把它换成了

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

现在它工作了:)

其他回答

在终端上执行以下命令确保ssh-agent正在运行:

eval $(ssh-agent -s)

来源:Github文档

确保你在.git/config中有正确的url

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

如果这是你第一次推,你需要在正确的上游设置

$ git push -u origin master

你可以检查哪个键被使用:

$ ssh -vvv git@github.com

回复应该包含如下内容:

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

也可以在~/中为ssh定义规则。Ssh /config,例如基于别名:

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

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

您可以为每个别名设置连接到不同的端口,使用不同的用户名等。

user@server:/etc/nginx$ cat .git/config 
...
[remote "origin"]
    url = git@gitlab.com:user/.git
    fetch = +refs/heads/*:refs/remotes/origin/*
...

使用ssh代替https。 在git中使用ssh密钥(添加ssh密钥)。 如果您是root用户,请使用ssh密钥。


$ sudo ssh-keygen
$ cat /root/.ssh/id_rsa.pub 

$ git init
$ git add file
$ git commit -m "add first file"
$ git remote add origin git@gitlab.com:user/example.git 
$ git push -u origin master

我有同样的问题,一段时间后,我看到我在根用户(sudo -s)。希望这对某人有所帮助。

就我而言,我在办公室使用的是公司网络(没有互联网连接)。为了从github拉代码,我在gitbash中设置了https代理,然后使用https而不是ssh来拉代码,它工作得很好。然而,当涉及到推送代码时,https代理将不起作用。因此,切换到Internet网络(有Internet连接)或设置ssh代理可以解决这个问题。