[英]You are on a branch yet to be born
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?
主分支在哪里?
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.一如既往,Git 是对的,它只是有一种古怪的说法:当你创建一个存储库时,主分支实际上还不存在,因为它没有任何指向。
Have you tried committing something after your git init
?你有没有试过在你的
git init
之后提交一些东西? Adding a remote and pulling from it will also work, of course.当然,添加遥控器并从中拉出也可以。
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
git add someFile
然后commit -m "first commit"
最后用push origin master
i hope it helps我希望它有帮助
If someone reaches this part, I think you have no luck with the top answers.如果有人到达这一部分,我认为您对最佳答案不走运。 I got the same situation with OP too.
我也遇到了与 OP 相同的情况。 Try this:
尝试这个:
There is a way to initialize a new repo without actually committing any files:有一种方法可以在不实际提交任何文件的情况下初始化新的 repo:
git commit --allow-empty -m "Initialization"
If you happen to have --bare
repo, then the workaround is as this:如果您碰巧有
--bare
repo,则解决方法如下:
mkdir /tmp/empty_directory
git --work-tree=/tmp/empty_directory checkout --orphan master
git --work-tree=/tmp/empty_directory commit --allow-empty -m "Initialization"
rm -rf /tmp/empty_directory
It's because you wanted to那是因为你想
git init
in the root folder where you have the .gitignore file.在您拥有.gitignore文件的根文件夹中。 Create a subfolder and try there.
创建一个子文件夹并在那里尝试。
I had the same error message when I had multiple Windows Explorers open, both opened to the same existing local git repo.当我打开多个 Windows 资源管理器时,我收到了相同的错误消息,它们都打开到同一个现有的本地 git 存储库。
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).后来,在 Windows 资源管理器的第二个实例中,我尝试右键单击 --> 分支(以找出当前检出哪个分支)。 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.只需关闭第二个资源管理器即可解决问题,并且错误没有出现在第一个资源管理器中。
I had the same issue as the OP.我和 OP 有同样的问题。 Initially, I did the following:
最初,我做了以下工作:
md Project
cd Project
git init
git remote add origin git@domain.com:user/repo.git
All subsequent git
commands had the same errors as the OP.所有后续的
git
命令都有与 OP 相同的错误。
What worked for me was to delete the Project folder, and then issue the following command from the parent folder:对我有用的是删除项目文件夹,然后从父文件夹发出以下命令:
git clone http[s]://domain.com/user/repo.git Project
It then prompted me for my username and password to access the repo.然后它提示我输入我的用户名和密码来访问 repo。 Every
git
command asked for credentials, so I ran the following command:每个
git
命令都要求提供凭据,因此我运行了以下命令:
git config --global credential.helper wincred
The next git
command asked for my credentials, which were then stored in the Windows Credential Manager (visible via the Control Panel ).下一个
git
命令要求提供我的凭据,然后将这些凭据存储在Windows 凭据管理器中(通过控制面板可见)。 Now git
commands work without prompting for credentials.现在
git
命令无需提示输入凭据即可工作。
This is because you are uploading the git repository which has main
as it default branch.这是因为您正在上传具有
main
作为默认分支的 git 存储库。 But on bare repository the default branch the master
is the default branch.但是在裸存储库上,默认分支
master
是默认分支。 To fix this problem easy way, remove the base repository.要以简单的方式解决此问题,请删除基础存储库。 Run the following command.
运行以下命令。
git config --global init.defaultBranch main
Then create again the bare repository using the following command. git config --global init.defaultBranch main
然后使用以下命令再次创建裸仓库。
git init --bare
Try add the branch in the end尝试在最后添加分支
#!/bin/bash
TARGET="/home/user/repo"
GIT_DIR="/home/user/www.git"
BRANCH="master"
while read oldrev newrev ref
do
# only checking out the master (or whatever branch you would like to deploy)
if [ "$ref" = "refs/heads/$BRANCH" ];
then
echo "Ref $ref received. Deploying ${BRANCH} branch to production..."
git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f $BRANCH
else
# perform more tasks like migrate and run test, the output of these commands will be shown on the push screen
echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server."
fi
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.