【发布时间】:2020-03-01 17:54:10
【问题描述】:
在将 git global 配置为:
$ git config --global user.name "My Username"
$ git config --global user.email "myeamil.com"
$ git clone git@gitlab.com:our-projects/this-project.git
$ cd this-project
$ touch README.md
$ git add README.md
$ git commit -m "add README"
然后按照here 描述的步骤生成并添加一个ssh key(我实际上创建了一个ED25519 SSH keys)。但是确保正确添加 ssh 的测试失败了。
$ ssh -T git@our-projects/this-project.git
ssh: Could not resolve hostname gitlab.com:it-porto/transportation-mode-detection.git: Name or service not known
$ ssh -T git@our-projects
ssh: Could not resolve hostname gitlab.com:it-porto/transportation-mode-detection.git: Name or service not known
$ ssh -T git@this-project.git
ssh: Could not resolve hostname gitlab.com:it-porto/transportation-mode-detection.git: Name or service not known
我的 ssh 密钥目录的内容:
$ ls /home/user/.ssh/
id_ed25519 id_ed25519.pub id_rsa id_rsa.pub known_hosts known_hosts.old
我该如何解决这个问题?
编辑
我按照评论中的建议做了一个ssh -T git@gitlab.com,显示了一条欢迎消息,但这似乎不起作用,我不能git push 到遥控器。
$ssh -T git@gitlab.com
Welcome to GitLab, @user!
$git push origin master
Counting objects: 8, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (8/8), 45.49 KiB | 3.50 MiB/s, done.
Total 8 (delta 0), reused 0 (delta 0)
remote: GitLab:
remote: A default branch (e.g. master) does not yet exist for our-projects/this-project
remote: Ask a project Owner or Maintainer to create a default branch:
remote:
remote: https://gitlab.com/our-projects/this-project/-/project_members
remote:
To gitlab.com:our-project/tthis-project.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@gitlab.com:our-projects/this-project.git'
$ git remote -v
origin git@gitlab.com:our-projects/this-projectt.git (fetch)
origin git@gitlab.com:our-projects/this-projectt.git (push)
【问题讨论】:
-
您需要 ssh 命令中的 主机名,而不是存储库名称:
ssh -T git@gitlab.com -
啊,好的。他们说 gitlab.com 应该替换为实例名称“要测试是否正确添加了 SSH 密钥,请在终端中运行以下命令(将 gitlab.com 替换为 GitLab 的实例域):”
ssh -T git@gitlab.com -
当您在不同的域名下运行自己的 gitlab 软件副本时,该“实例名称”适用。
-
好的。我按照你说的做了,带有欢迎信息,但根据我的问题编辑,无法推送到远程。
-
谢谢@JoachimSauer 这让我搞砸了一个多小时。