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

前端 未结 30 1750
轮回少年
轮回少年 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:59

    This will also happen if you have a typo in the branch name you're trying to push.

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

    Missing or skipping git add . or git commit may cause this error:

    git push -u origin master
    Username for 'https://github.com': yourusername
    Password for 'https://yourusername@github.com': 
    error: src refspec master does not match any.
    error: failed to push some refs to 'https://github.com/yourusername/foobar.git'
    

    To fix it, reinitialize and follow the proper sequence:

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

    Make sure you've added first, and then commit/ push:

    Like:

    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:02

    In the scenario where you check out the code from an external repository (GitHub), and want to import it in personal / internal system, this command really shines:

    git push --all origin
    

    This pushes all local branches to the remote, without checking refs and without insisting on commits.

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

    For me I had to make sure the public key is properly configured on the server (appended in ~/.ssh/authorized_keys) and in GitHub/Bitbucket (added to my SSH keys on GitHub or Bitbucket) - they need to match.

    Then:

    git add --all :/
    
    git commit -am 'message'
    
    git push -u origin master
    

    It worked for me in the end.

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

    If you get this error while working in detached HEAD mode, you can do this:

    git push origin HEAD:remote-branch-name
    

    See also: Making a Git push from a detached head

    If you are on a different local branch than the remote branch, you can do this:

    git push origin local-branch-name:remote-branch-name
    
    0 讨论(0)
提交回复
热议问题