git 不是有效的对象名称:'master'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36739029/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 11:57:15  来源:igfitidea点击:

Not a valid object name: 'master'

gitgit-branchgit-bash

提问by M Fuat NURO?LU

I created new directory testand CDinto it
Creating new Repository into it :

我创建了新的目录testCD到其中
创建新的存储库:

git init

Creating one text file test.txtand one directory with another text file inside it mydir/newfile.txt:

创建一个文本文件test.txt和一个目录,其中包含另一个文本文件mydir/newfile.txt

echo "Hello" > test.txt 
mkdir mydir
echo "hello" > mydir/newfile.txt
git add test.txt
git add mydir/newfile.txt
git commit

After these steps when i want to have a branch by writing :

在这些步骤之后,当我想通过编写分支时:

git branch new_branch

I have the error :

我有错误:

fatal: Not a valid object name: 'master'

致命:不是有效的对象名称:'master'

采纳答案by M Fuat NURO?LU

Thanks for everyone.
I just had to define my email and username by these two lines and everything worked :

谢谢大家。
我只需要通过这两行定义我的电子邮件和用户名,一切正常:

$ git config --global user.name "username"  
$ git config --global user.email "[email protected]"

回答by Naanii

Try with this

试试这个

git commit -m "initial commit"

git push -u origin

It will work. if you are facing any issues please share your error, so that we can find the issues and help you.

它会起作用。如果您遇到任何问题,请分享您的错误,以便我们找到问题并帮助您。

回答by Aditya Kumar Pandey

I ran the same commands as you did. Instead of git commit, you could type

我和你一样运行了相同的命令。代替 git commit,你可以输入

git commit -m "Initial check-in"

And, after that master branch would be set. And, then you could type 'git branch new_branch' and it would work as expected.

并且,在那之后将设置主分支。然后,您可以键入“git branch new_branch”,它会按预期工作。

The reason why it didn't work for you is that git commit didn't work for you and so the initial branch wasn't set. If you want to use 'git commit', then type some message in it. After that, it should work too.

它对您不起作用的原因是 git commit 对您不起作用,因此未设置初始分支。如果您想使用“git commit”,请在其中键入一些消息。在那之后,它也应该工作。