Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
$ 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:
Pull your repo in another directory
copy .git folder to your new repo
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
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
–
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.
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.
while read oldrev newrev ref
# only checking out the master (or whatever branch you would like to deploy)
if [ "$ref" = "refs/heads/$BRANCH" ];
echo "Ref $ref received. Deploying ${BRANCH} branch to production..."
git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f $BRANCH
# 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."
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.