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

前端 未结 30 1710
轮回少年
轮回少年 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 03:13

    I faced the same problem, and I used --allow-empty:

    $ git commit -m "initial commit" --allow-empty
    ...
    $ git push
    ...
    

    Supplement

    One of main reasons of this problem is that some Git servers, such as BitBucket, don't have their master branch initialized when a fresh repository is cloned.

    0 讨论(0)
  • 2020-11-22 03:14

    Short answer: This error means the branch you want to push in remote doesn't exist!

    In my case, starting from October-2020, the repos created since then had the main branch instead of the previous master branch. So all I had to do this:

    git push -u origin main 
    
    • you may skip -u flag if the upstream is set( Like in case you had cloned it already)

    Bingo! That worked for me! Hope that helps! Happy coding!

    0 讨论(0)
  • 2020-11-22 03:15
    1. My changes were already committed
    2. Force push still gave me the same error.

    So I tried Vi's solution:

    git push origin HEAD:<remoteBranch> 
    

    This worked for me.

    0 讨论(0)
  • 2020-11-22 03:18

    To check the current status, git status.

    And follow these steps as well:

    git init
    git add .
    git commit -m "message"
    git remote add origin "github.com/your_repo.git"
    git push -u origin master
    
    0 讨论(0)
  • 2020-11-22 03:19

    I had the same problem when I missed to run:

    git add .
    

    (You must have at least one file, or you will get the error again.)

    0 讨论(0)
  • 2020-11-22 03:19

    I had the same problem. I did it by the following steps:

    1. git commit -m 'message'
    2. git config --global user.email "your mail"
    3. git config --global user.name "name"
    4. git commit -m 'message'
    5. git push -u origin master
    
    0 讨论(0)
提交回复
热议问题