简体   繁体   中英

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.

Have you tried committing something after your 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

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. Try this:

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

There is a way to initialize a new repo without actually committing any files:

git commit --allow-empty -m "Initialization"

If you happen to have --bare repo, then the workaround is as this:

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. 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.

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.

I had the same issue as the 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.

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. Every git command asked for credentials, so I ran the following command:

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 ). Now git commands work without prompting for credentials.

This is because you are uploading the git repository which has main as it default branch. But on bare repository the default branch the master is the default branch. 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 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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