我正在尝试向Gitlab推送一个git repo。
我有——global git和ssh设置,我使用的工作。我遇到的一个repo是一个个人项目,所以我想使用不同的user.name
和user.email
git配置设置和不同的ssh密钥对我的全局工作配置。
我已经设置了user.name
和user.email
在git仓库(没有——global开关)使用:
git config user.name "my gitlab username"
git config user.email "my gitlab registered email address"
我已经将git配置设置为使用本地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
任何和所有的帮助感谢…
实际的URL应该是:
git remote add origin git@gitlab.com:username/project.git
# not:
git remote add origin git@gitlab.com:project.git
仔细检查GitLab上的远程存储库是否使用默认分支main
创建,而您的本地分支可能是master
。
如果是这种情况,请尝试:
git push -u origin master:main
自2021年3月10日起,GitLab可以使用main
作为新的存储库。
每个Git存储库都有一个初始分支,这是生成新存储库时创建的第一个分支。从历史上看,这个初始分支的默认名称是
master
.
这个术语来自Bitkeeper, Git的前身。Bitkeeper将真相的来源称为"主存储库"。和其他副本作为"奴隶库"。
这显示了主/从引用在技术中是多么常见,以及了解术语master应该如何解释的困难。Git项目维护者与更广泛的社区协调,一直在听取开发社区的反馈,为默认分支确定一个更具描述性和包容性的名称,并为用户提供更改其存储库默认分支名称(通常为
master
)的选项。