程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了不使用全局设置将 git repo 推送到 Gitlab大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决不使用全局设置将 git repo 推送到 Gitlab?

开发过程中遇到不使用全局设置将 git repo 推送到 Gitlab的问题如何解决?下面主要结合日常开发的经验,给出你关于不使用全局设置将 git repo 推送到 Gitlab的解决方法建议,希望对你解决不使用全局设置将 git repo 推送到 Gitlab有所启发或帮助;

我正在尝试将 git repo 推送到 Gitlab。

我有用于工作的 --global git 和 ssh 设置。我遇到问题的一个存储库是个人项目,因此我想对我的全局工作配置使用不同的 user.nameuser.email git 配置设置和不同的 ssh 密钥对。

我在 git repo 中设置了 user.nameuser.email(没有 --global 开关)使用:

git config user.name "my gitlab username"
git config user.email "my gitlab registered email address"
@H_674_19@

我已经将 git config 设置为使用本地 ssh 密钥文件而不是系统密钥文件:

git config core.sshCommand "ssh -o IDentitIEsOnly=yes -i ~/path-to-ed25519 -F /dev/null"
@H_674_19@

在 gitlab 上,我创建了一个与本地存储库同名的存储库,并添加了 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
@H_674_19@

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
@H_674_19@

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
@H_674_19@

感谢任何和所有帮助...

解决方法

实际网址为:

 git remote add origin git@gitlab.com:username/project.git
 # not: 
 git remote add origin git@gitlab.com:project.git
@H_674_19@

仔细检查 GitLab 上的远程存储库是否是使用默认分支 @H_112_5@main 创建的,而您的本地分支可能是 @H_112_5@master。
如果是这种情况,请尝试:

git push -u origin master:main
@H_674_19@

自 2021 年 3 月 10 日起,GitLab can use @H_112_5@main for new repositories。

每个 Git 存储库都有一个初始分支,这是生成新存储库时要创建的第一个分支。过去,这个初始分支的默认名称是 @H_112_5@master。
这个术语来自 Bitkeeper,它是 Git 的前身。 Bitkeeper 将真实来源称为“主存储库”,将其他副本称为“从存储库”。
这表明主/从引用在技术中是多么常见,并且很难知道如何解释术语主。

Git 项目维护者与更广泛的社区合作,一直在听取开发社区的反馈,以确定默认分支的更具描述性和包容性的名称,并为用户提供更改默认分支名称的选项(通常为@H_112_5@master) 的存储库。

大佬总结

以上是大佬教程为你收集整理的不使用全局设置将 git repo 推送到 Gitlab全部内容,希望文章能够帮你解决不使用全局设置将 git repo 推送到 Gitlab所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:repo推送到