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?

I accidentally ran npm version patch on the parent folder which I think is what messed up all my projects Scott Morrison Aug 15, 2022 at 16:57

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 added a remote and pulled from it and I still got this error. Simply just doing a quick add . / commit I was able to get to branches Tim Roberts Sep 25, 2015 at 23:01 @Cocuba I think you don`t have to pull from master, it says when your just init your git repo, you should make your first commits to create a branch, before you can checkout, since branch have not been created. MichaelMao Jun 6, 2018 at 3:45

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
                    This works for me with the additional step of forcibly updating the new master branch to what I was trying to make it in the first place (in my case via git push -f from another repo with the new one as a remote). This abandoned the pro forma commit, but I never wanted it in the first place, so whatever.
    – BCS
                    Jan 22 at 17:19
    

    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.