可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
Im have strange problem:
$ cd ~/htdocs $ mkdir test $ cd test $ git init Initialized empty Git repository in /home/deep/htdocs/test/.git/ $ git checkout master error: pathspec 'master' did not match any file(s) known to git. $ git checkout -b master fatal: You are on a branch yet to be born $ git checkout origin/master error: pathspec 'origin/master' did not match any file(s) known to git. $ git branch -a (empty this)
But this is new local empty repo. Where is master branch?
回答1:
As ever, Git is right, it just has a quirky way of saying it: when you create a repository, the master branch actually doesn't exist yet because there's nothing for it to point to.
Have you tried committing something after your git init
? Adding a remote and pulling from it will also work, of course.
回答2:
I had the same problem as you. The way I solved was creating a new empty file just to have a file in the project.
git add someFile
then commit -m "first commit"
and finally with push origin master
i hope it helps
回答3:
I had the same error message when I had multiple Windows Explorers open, both opened to the same existing local git repo.
I created a new branch in one window, by using right-click --> create branch.
Later, in the 2nd instance of Windows Explorer, I attempted to right click --> Branch (to find out which branch was currently checked out). I then got the message "You are on a branch yet to be born".
Simply closing the 2nd Explorer ended the problem, and the error did not show up in the 1st Explorer.
回答4:
If someone reaches this part, I think you have no luck with the top answers. I got the same situation with OP too. Try this:
- Pull your repo in another directory
- copy .git folder to your new repo