【发布时间】:2021-03-14 10:07:38
【问题描述】:
我正在尝试将 git repo 推送到 Gitlab。
我有用于工作的 --global git 和 ssh 设置。我遇到问题的一个仓库是一个个人项目,所以我想对我的全局工作配置使用不同的 user.name 和 user.email git 配置设置和不同的 ssh 密钥对。
我在 git repo 中设置了 user.name 和 user.email(没有 --global 开关),使用:
git config user.name "my gitlab username"
git config user.email "my gitlab registered email address"
我已将 git config 设置为使用本地 ssh 密钥文件,而不是使用系统文件:
git config core.sshCommand "ssh -o IdentitiesOnly=yes -i ~/path-to-ed25519 -F /dev/null"
在 gitlab 上,我创建了一个与本地 repo 同名的 repo,并添加了 ssh 公钥。
Gitlab 推荐这些命令来推送项目:
cd existing_repo
git remote rename origin old-origin
git remote add origin git@gitlab.com:project.git
git push -u origin --all
git push -u origin --tags
git remote add origin git@gitlab.com:project.git 命令似乎成功了,至少没有错误。
git push -u origin --all 命令失败,输出如下:
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: the remote end hung up unexpectedly
Everything up-to-date
Gitlab 建议使用 ssh -T git@gitlab.example.com 测试 ssh 设置,但我不清楚如何从 repo url 填充 example.com。我已经尝试了所有明显的组合,但没有任何乐趣。我还尝试了 -i 选项来指定要使用的私钥和 -Tvvv 选项而不是 -T 选项,但不清楚这是否有效。输出如下:
OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n 7 Dec 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolving "gitlab.com:username/project" port 22
ssh: Could not resolve hostname gitlab.com:username/project: Name or service not known
任何和所有帮助表示赞赏...
【问题讨论】:
-
问题标题应该说“不使用”而不是“不使用”。似乎无法编辑我自己的问题。如果有模组阅读,请修复并删除此评论。
-
为什么不对两个 repo 使用相同的密钥?其他解决方案,将 ssh 用于您的公共存储库并使用 http 凭证作为特定存储库。
-
我觉得http现在贬值了?至少 Pycharm 一直在唠叨我不要再使用它了。
-
user.name和user.email不用于身份验证(使用 ssh 或 https)。 (其余评论已删除,我明白我现在误解了什么) -
最后的
ssh失败是因为你跑了ssh -T git@gitlab.com:username/project;你需要ssh -T git@gitlab.com,除非你的core.sshCommand设置受到尊重,你需要 ssh -T -o IdentitiesOnly=yes -i ...`(基本上是你在这里设置的所有选项)。