Message 'src refspec master does not match any' when pushing commits in Git

前端 未结 30 1712
轮回少年
轮回少年 2020-11-22 02:49

I clone my repository with:

git clone ssh://xxxxx/xx.git 

But after I change some files and add and commit them,

相关标签:
30条回答
  • 2020-11-22 02:56
    1. Try git show-ref to see what refs you have. Is there a refs/heads/master?

    Due to the recent "Replacing master with main in GitHub" action, you may notice that there is a refs/heads/main. As a result, the following command may change from git push origin HEAD:master to git push origin HEAD:main

    1. You can try git push origin HEAD:master as a more local-reference-independent solution. This explicitly states that you want to push the local ref HEAD to the remote ref master (see the git-push refspec documentation).
    0 讨论(0)
  • 2020-11-22 02:56

    To fix it, re-initialize and follow the proper code sequence:

    git init
    git add .
    git commit -m 'message'
    git push -u origin master
    
    0 讨论(0)
  • 2020-11-22 02:56

    It happens if you forget to commit before pushing for the first time. Just run:

    git commit -m "first commit"
    
    0 讨论(0)
  • 2020-11-22 02:58

    In my case, I forgot to include the .gitignore file. Here are all the steps required:

    1. Create an empty Git repository on remote,
    2. On local create the .gitignore file for your project. GitHub gives you a list of examples here
    3. Launch a terminal, and in your project do the following commands:

      git remote add origin YOUR/ORIGIN.git
      
      git add .
      
      git commit -m "initial commit or whatever message for first commit"
      
      git push -u origin master
      
    0 讨论(0)
  • 2020-11-22 02:58

    This just mean you forgot to do the initial commit, try

    git add .
    git commit -m 'initial commit'
    git push origin master
    
    0 讨论(0)
  • 2020-11-22 02:59
    git push -u origin master
    error: src refspec master does not match any.
    

    For that you need to enter the commit message as follows and then push the code:

    git commit -m "initial commit"
    
    git push origin master
    

    Successfully pushed to master.

    0 讨论(0)
提交回复
热议问题