【问题标题】:git push -u origin main error (other name than master)git push -u origin main 错误(除 master 以外的其他名称)
【发布时间】:2020-11-23 07:41:23
【问题描述】:

git的命名约定已经改变,现在建议为Master分支使用其他命名。

我在尝试将我很棒的项目初始化为一个名为 Main

的新 git 存储库时遇到了一个问题
git init
git add -A
git remote add origin https://github.com/{MYREPO}.git
git push -u origin main

最终抛出以下错误

error: src refspec main does not match any.
error: failed to push some refs to 'https://github.com/{MYREPO}.git'

git 版本 2.16.1.windows.4

【问题讨论】:

    标签: git rename naming-conventions git-push


    【解决方案1】:

    解决方案假设这是全新的回购,这就是解决方案

    git branch -m master main
    git push -u origin main
    

    说明

    git init 创建一个名为 master (ref) 的本地源

    -b <branch-name
    --initial-branch=<branch-name>
    

    为新创建的存储库中的初始分支使用指定的名称。

    如果未指定,则回退到 默认名称:master

    这就是 git 抛出该错误的原因。

    使用git show-ref 来查看您有哪些参考资料。 (ref)

    如果它显示refs/heads/master,您可以使用git branch -m master {name} 将其重命名为您想要的任何名称

    【讨论】:

    • 为什么我会得到! [rejected] main -&gt; main (non-fast-forward)?我在git show-ref 中有以下内容:refs/heads/mainrefs/remotes/origin/master,我所有的文件都在master 中,我希望它们在main 中。似乎这个更改名称的事情对 git 的新手没有帮助,这对我来说已经很复杂了。
    • @BrianWiley 我认为您需要按照 git documentation 中描述的说明运行 $ git remote rename master main
    • 谢谢,我一直在使用these 指令,它可能适用于任何项目,而不仅仅是 R。这样做是不是更难?
    • 不管是 R 语言还是其他语言,git 对任何东西都应该是一样的。上面的命令你试过了吗?
    猜你喜欢
    • 2018-07-30
    • 2011-08-07
    • 1970-01-01
    • 2021-04-13
    • 2019-08-27
    • 2020-07-30
    • 1970-01-01
    • 2023-02-02
    • 1970-01-01
    相关资源
    最近更新 更多