首页 文章

在git中推送提交时,src refspec master与任何命令都不匹配

提问于
浏览
2035

我克隆了我的存储库:

git clone ssh://xxxxx/xx.git

但是在我更改了一些文件和 addcommit 之后我想将它们推送到服务器:

git add xxx.php
git commit -m "TEST"
git push origin master

但我得到的错误是:

error: src refspec master does not match any.  
error: failed to push some refs to 'ssh://xxxxx.com/project.git'

30 回答

  • 9
    • 我的更改已提交

    • Force push仍然给了我同样的错误 .

    所以我试了Vi's solution

    git push origin HEAD:<remoteBranch>
    

    这对我有用 .

  • 194

    我有同样的问题 . 我按照以下步骤来做

    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
    

    希望它会帮助任何人

  • 158

    just add a initial commit ,follow steps:-

    • git add .

    • git commit -m“initial commit”

    • git push origin master

    这对我有用

  • 6

    也许你只需要提交 . 我做的时候碰到了这个:

    mkdir repo && cd repo
    git remote add origin /path/to/origin.git
    git add .
    

    哎呀!从不承诺!

    git push -u origin master
    error: src refspec master does not match any.
    

    我所要做的就是:

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

    成功!

  • 58

    Try this:

    git add .
    
    git commit -m "your commit message"
    
    git remote add origin *remote repository URL*
    
    git push origin *your-branch-name*
    
  • 12

    对我来说,我必须确保 public key 在服务器中正确配置(附加在〜/ .ssh / authorized_keys中)和github / bitbucket(添加到我在github或bitbucket上的SSH密钥) - 它们需要匹配 .

    然后:

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

    最后为我工作 .

  • 39

    如果在分离HEAD模式下工作时出现此错误,则可以执行以下操作:

    git push origin HEAD:remote-branch-name
    

    另见:making a git push from a detached head

    如果您位于与远程分支不同的本地分支上,则可以执行以下操作:

    git push origin local-branch-name:remote-branch-name
    
  • 6

    git add .

    是你需要的所有代码跟踪你的目录中的所有未跟踪文件

  • 3202

    缺少或跳过 git add .git commit 可能会导致此错误:

    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'
    

    要修复它,请重新初始化并遵循正确的顺序:

    git init
    git add .
    git commit -m 'message'
    git *create remote
    git push -u origin master
    
  • 10

    当您在特定分支中并尝试推送另一个尚不存在的分支时,也会发生这种情况,例如:

    $ git branch
    * version-x  # you are in this branch
      version-y
    
    $ git push -u origin master
    error: src refspec master does not match any.
    error: failed to push some refs to 'origin_address'
    
  • 83

    添加文件,忘记提交和推送时会发生这种情况 . 所以提交文件然后推送 .

  • 8

    在提交之后和推送之前我忘了做一个“git pull origin master”它导致了同样的问题:“当在git中提交提交时,src refspec master不匹配” . 那么,你应该做的是:

    1. git add .
    2. git pull origin master
    3. git commit -am "Init commit"
    4. git push origin master
    
  • 8

    确保先添加,然后提交/推送:

    喜欢:

    git init
    git add .
    git commit -m "message"
    git remote add origin "github.com/your_repo.git"
    git push -u origin master
    
  • 17

    在git只添加了一个目录后,我发现这发生在一个全新的存储库中 .

    一旦我添加了一个文件(例如README),git push就能很好地工作 .

  • 10

    要修复它,请重新初始化并遵循正确的代码序列:

    git init
    git add .
    git commit -m 'message'
    git push -u origin master
    
  • 630

    我错过了跑步时遇到了同样的问题:

    git add .
    

    (您必须至少有一个文件,否则您将再次收到错误)

  • 7

    我在添加空目录时遇到了这个问题 . Git不允许推送空目录 . 这是一个简单的解决方案 .

    在要推送到远程的目录中创建文件.gitkeep,并从命令行提交“空”目录:

    touch your-directory/.gitkeep
    git add your-directory/.gitkeep
    git commit -m "Add empty directory"
    
  • 12

    我认为这是因为你推了一个无效的分支 . 通常因为存储库没有公共主分支(可能是开发分支) . 你可以使用git branch来查看分支 .

  • 7

    这对我来说重置为远程主控回购

    git checkout master
    git commit -a -m "your comment"
    git push origin master
    
  • 7

    如果你是第一次使用它,你需要配置你的git:

    git config --global user.email "you@example.com"
    
    git config --global user.name "Your Name"
    
  • 17
    • 试试 git show-ref 看看你有什么裁判 . 是 refs/heads/master

    • 您可以尝试使用 git push origin HEAD:master 作为更多与本地参考无关的解决方案 . 这明确指出您要将本地ref HEAD 推送到远程ref master (请参阅git-push refspec文档) .

  • 101

    如果您在执行git init并推送初始提交后遇到此问题 . 您可以尝试以下方式,

    git checkout -b "new branch name"
    git push origin "new branch name"
    

    您的代码将作为新分支推送 .

  • 63

    如果您尝试推送的分支名称中有拼写错误,也会发生这种情况 .

  • 17

    此问题的另一个可能原因是您拼错了分支名称 . 所以如果你做了我做的事情,那么问题将通过纠正:

    git push origin mater
    

    git push origin master
    
  • 14

    我的问题是“主”分支尚未在本地创建 .

    快点

    git checkout -b "master"
    

    创建了主分支,在这一点上,快速:

    git push -u origin master
    

    推动工作到git repo .

  • 8

    我遇到了同样的问题而且我使用了 --allow-empty .

    $ git commit -m "initial commit" --allow-empty
    ...
    $ git push
    ...
    
  • 44
    • 第一个git add .

    • 秒git commit -m "message"

    • 第三个git push origin分支请检查拼写错误,因为这也可能会出错 .

  • 25

    删除本地计算机中的所有文件后,我也遇到了类似的错误,我必须清理存储库中的所有文件 .

    我的错误信息是这样的:

    error: src refspec master does not match any.
    error: failed to push some refs to 'git@github ... .git'
    

    并通过执行以下命令解决:

    touch README
    git add README
    
    git add (all other files)
    git commit -m 'reinitialized files'
    git push origin master --force  # <- caution, --force can delete others work.
    

    就是这样,希望这会有所帮助 .

  • 62
    git push -u origin master
    error: src refspec master does not match any.
    

    为此,您需要输入如下的提交消息,然后按下代码

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

    成功地推到掌握

  • 12

    这只是意味着你忘了做初始提交,试试

    git add .
    git commit -m 'initial commit'
    git push origin master
    

相关问题