You are on a branch yet to be born

匿名 (未验证) 提交于 2019-12-03 08:33:39

问题:

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:

  1. Pull your repo in another directory
  2. copy .git folder to your new repo


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!