Reputation: 2512
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?
Upvotes: 65
Views: 119314
Reputation: 382
In case someone is getting this error while cloning a repository as a submodule, you may consider using the -b
switch, to specify the divergent default branch, i.e. git submodule add -b main git://some/repository
Upvotes: 1
Reputation: 661
This is because you are uploading the git repository which has main
as it default branch. But on bare repository the default branch is 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 init --bare
Upvotes: 7
Reputation: 706
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
Upvotes: 1
Reputation: 23
It's because you wanted to
git init
in the root folder where you have the .gitignore file. Create a subfolder and try there.
Upvotes: 2
Reputation: 792
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
Upvotes: 3
Reputation: 9461
I had the same issue as the OP. Initially, I did the following:
md Project
cd Project
git init
git remote add origin [email protected]: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.
Upvotes: 0
Reputation: 188
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:
Upvotes: 6
Reputation: 199
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.
Upvotes: 0
Reputation: 560
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
Upvotes: 9
Reputation: 19675
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.
Upvotes: 45