You are on a branch yet to be born

Git

Git Problem Overview


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?

Git Solutions


Solution 1 - Git

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.

Solution 2 - Git

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

Solution 3 - Git

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

Solution 4 - Git

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

Solution 5 - Git

It's because you wanted to

git init

in the root folder where you have the .gitignore file. Create a subfolder and try there.

Solution 6 - Git

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

Solution 7 - Git

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.

Solution 8 - Git

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDeepView Question on Stackoverflow
Solution 1 - GitWander NautaView Answer on Stackoverflow
Solution 2 - GitYorshView Answer on Stackoverflow
Solution 3 - GitFebrinanda Endriz PratamaView Answer on Stackoverflow
Solution 4 - GitStoinovView Answer on Stackoverflow
Solution 5 - GitTamás GráblerView Answer on Stackoverflow
Solution 6 - GitUsama ImdadView Answer on Stackoverflow
Solution 7 - Gitsboggs11View Answer on Stackoverflow
Solution 8 - GitJames L.View Answer on Stackoverflow