我试图设置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。如果是这样,我不知道如何改变这一点,或者如果我可以推下一个别名


当前回答

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

其他回答

对我来说,这是因为网络。您的网络可能很慢。所以更换网络或排除故障。

您可以指定SSH应该发送到远程系统的用户名作为远程URL的一部分。在远程主机名之前输入用户名,后面加@。

git remote set-url website abc@***.com:path/to/repo

2020年10月更新

在大多数情况下,当您有多个用户从同一个客户端系统访问同一个git服务器时,该时间git服务器将访问密钥与用户混淆,但当您发出命令时,它将使用默认用户。

ssh -T git@gitlab.com

看看哪些用户是你想要积极推动的用户

简单的解决方案是从git服务器中删除未使用的用户公钥。

然后试着去取或拉,推它会为我工作

我解决了这个问题,改变我的url从

https://gitlab.com/{gitlab_user}/project_repo.git

to

https://{gitlab_user}@gitlab.com/gitlab_user/project_repo.git

使用命令

git remote set-url https://{gitlab_user}@gitlab.com/gitlab_user/project_repo.git

尝试使用未设置的GIT_SSH删除GIT_SSH环境变量。这就是我的问题所在。