error: src refspec master does not match any

后端 未结 21 1108
别跟我提以往
别跟我提以往 2020-12-22 17:38

I have tried to follow the solutions suggested in this post but it didnt work and I am still getting: src refspec master does not match any.

Here is what I did: Fo

相关标签:
21条回答
  • 2020-12-22 18:10

    FWIW, ran into same error, but believe it came about due to the following sequence of events:

    • Remote Git repo was created with master branch.
    • Local clone was then created.
    • Remote Git repo was then modified to include a dev branch, which was defined as the default branch, in conjunction with permissions added to the master branch preventing changes without a pull request.
    • Code updates occurred in the local clone, ready to be pushed to the remote repo.

    Then, when attempting to push changes from the local to the remote, received error "src refspec master does not match any", or when attempting to push to dev, "src refspec dev does not match any".

    Because changes were pending in the local clone, I did not want to blast it and refresh. So, fixed the issue by renaming the local branch to dev...

    $ git branch -m dev

    ...followed by the normal push of git push origin dev, which worked this time without throwing the aforementioned error.

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

    Try following command:

    git push origin HEAD:master
    

    Git threw the below error when I tried simply git push. So clearly this is because Git matches the local and remote branch while pushing commits. This is the push.default behavior, you can find out more details here.

    fatal: The upstream branch of your current branch does not match
    the name of your current branch.  To push to the upstream branch
    on the remote, use
    
        git push origin HEAD:<Branch_Name>
    
    To push to the branch of the same name on the remote, use
    
        git push origin <Branch_Name>
    
    To choose either option permanently, see push.default in 'git help config'.
    
    0 讨论(0)
  • 2020-12-22 18:11

    For a new repository, the method works for me:

    1. Remote the files related with git
      rm -rf .git

    2. Do the commit again
      git add . && git commit -m "your commit"

    3. Add the git URL and try to push again
      git remote add origin <your git URL>

    4. And then try to push again
      git push -u origin master -f

    5. Success!

    Since it's a new repository, so it doesn't matter for me to remove the git and add it again.

    0 讨论(0)
  • 2020-12-22 18:12

    This error can typically occur when you have a typo in the branch name.

    For example you're on the branch adminstration and you want to invoke: git push origin administration.

    Notice that you're on the branch without second i letter: admin(i)stration, that's why git prevents you from pushing to a different branch!

    0 讨论(0)
  • 2020-12-22 18:12

    I had already committed the changes and added all the files, had the same origin as remote, still kept getting that error. My simple solution to this was just:

    git push
    
    0 讨论(0)
  • 2020-12-22 18:16

    This is happend to me once I forgot to add files. So I got the same error. All you need to do is add your files.

    1. Add your files => git add . or the name of the files you want to add. you supposed to init first your repo with git init.
    2. Commit your changes => git commit -m 'Initial Commit'.
    3. Now push your changes => git push -u origin master
    0 讨论(0)
提交回复
热议问题