简体   繁体   English

Git 错误“致命:无效的分支名称:init.defaultBranch =”

[英]Git Error "fatal: invalid branch name: init.defaultBranch ="

I getting this error when ever I do git clone当我执行git clone时出现此错误

Error:- fatal: invalid branch name: init.defaultBranch =错误:- fatal: invalid branch name: init.defaultBranch =

Tried to reinstall git (latest)尝试重装git(最新)

Still same error还是一样的错误

OS:- Windows操作系统:- Windows

Git CMD 日志

It would appear that you have experimented with the new (2.28) init.defaultBranch configuration value .您似乎已经尝试过新的 (2.28) init.defaultBranch配置值

Assign it a proper value:为其分配一个适当的值:

git config --global init.defaultBranch main

Got it知道了

Enter this in terminal在终端输入这个

git config --global init.defaultBranch master

With Git 2.30 (Q1 2021), this should be clearer, as the users are trained to prepare for future change of init.defaultBranch configuration variable.在 Git 2.30(2021 年第一季度)中,这应该更清楚,因为用户经过培训,可以为init.defaultBranch配置变量的未来更改做好准备。

See commit 675704c , commit cc0f13c , commit cfaff3a , commit 1296cbe (11 Dec 2020) by Johannes Schindelin ( dscho ) .请参阅Johannes Schindelin ( dscho ) 的commit 675704ccommit cc0f13ccommit cfaff3acommit 1296cbe (2020 年 12 月 11 日
(Merged by Junio C Hamano -- gitster -- in commit 772bdcd , 18 Dec 2020) (由Junio C gitster合并gitster 提交 772bdcd ,2020 年 12 月 18 日)

init : provide useful advice about init.defaultBranch init : 提供关于init.defaultBranch有用建议

Signed-off-by: Johannes Schindelin签字人:约翰内斯·辛德林

To give ample warning for users wishing to override Git's the fall-back for an unconfigured init.defaultBranch (in case we decide to change it in a future Git version), let's introduce some advice that is shown upon git init ( man ) when that value is not set.为了给希望覆盖 Git 的用户提供充足的警告,这是未配置的init.defaultBranch (以防我们决定在未来的 Git 版本中更改它),让我们介绍一些在git init ( man ) 上显示的建议值未设置。

Note: two test cases in Git's test suite want to verify that the stderr output of [ git init ](https://github.com/git/git/blob/675704c74dd4476f455bfa91e72eb9e163317c10/Documentation/git-init.txt)<sup>([man](https://git-scm.com/docs/git-init))</sup> is empty.注意:两个测试用例在GIT中的测试套件要验证stderr的输出[ GIT中的init ](https://github.com/git/git/blob/675704c74dd4476f455bfa91e72eb9e163317c10/Documentation/git-init.txt)<sup>([man](https://git-scm.com/docs/git-init))</sup>为空。
It is now necessary to suppress the advice, we now do that via the init.defaultBranch setting.现在有必要取消建议,我们现在通过init.defaultBranch设置来做到这init.defaultBranch While not strictly necessary, we also set this to false in test_create_repo() .虽然不是绝对必要的,但我们还在test_create_repo()设置为false

The advice now is:现在的建议是:

Using '%s' as the name for the initial branch.使用“%s”作为初始分支的名称。

This default branch name is subject to change.此默认分支名称可能会更改。
To configure the initial branch name to use in all of your new repositories, which will suppress this warning, call:要配置在所有新存储库中使用的初始分支名称,这将抑制此警告,请调用:

 git config --global init.defaultBranch <name>

Names commonly chosen instead of ' master ' are ' main ', ' trunk ' and ' development '.通常选择代替“ master ”的名称是“ main ”、“ trunk ”和“ development ”。
The just-created branch can be renamed via this command:可以通过以下命令重命名刚刚创建的分支:

 git branch -m <name>

And:和:

init : document init.defaultBranch better init : 文件init.defaultBranch更好

Initial-patch-by: Junio C Hamano初始补丁:Junio C Hamano
Signed-off-by: Johannes Schindelin签字人:约翰内斯·辛德林

Our documentation does not mention any future plan to change 'master' to other value.我们的文档没有提到将“master”更改为其他值的任何未来计划。 It is a good idea to document this, though.不过,记录下来是个好主意。

git init now includes in its man page : git init现在包含在其手册页中

An initial branch without any commits will be created (see the --initial-branch option below for its name).将创建一个没有任何提交的初始分支(有关其名称,请参阅下面的--initial-branch选项)。

git init now includes in its man page : git init现在包含在其手册页中

--initial-branch

Use the specified name for the initial branch in the newly created repository.为新创建的存储库中的初始分支使用指定的名称。
If not specified, fall back to the default name (currently master , but this is subject to change in the future; the name can be customized via the init.defaultBranch configuration variable).如果未指定,则回退到默认名称(当前是master ,但将来可能会更改;该名称可以通过init.defaultBranch配置变量进行自定义)。

I was having same error during react App Deployment on Git-hub pages我在 Git-hub 页面上反应应用程序部署期间遇到了同样的错误

tried code : git config ---global init.defaultBranch master尝试过的代码: git config ---global init.defaultBranch master

You can set it to a value as mentioned in @CodeCaster's comment .您可以将其设置为@CodeCaster 的评论中提到的值。

But It would make life easier is you just unset that value so that the default configured one from the remote will be chosen.但是,如果您只是取消设置该值,以便选择远程配置的默认值,这会使生活更轻松。

You can either use the follwoing command:您可以使用以下命令:

git config --unset --global init.defaultBranch 

Or remove the corresponding config line from ~/.gitconfig file.或者从~/.gitconfig文件中删除相应的配置行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM