【问题标题】:Push origin master error on new repository在新存储库上推送源主错误
【发布时间】:2010-10-24 01:31:38
【问题描述】:

我刚开始在 github 上使用 git。我按照他们的指示在最后一步遇到了错误。我正在检查当前不受源代码控制的现有目录(大约一周前的项目)。除此之外,我的用例应该很正常。

这是发生了什么:

$ git push origin master
error: src refspec master does not match any.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to 'git@github.com:{username}/{projectname}.git'

Github 使用说明:

Global setup:

  Download and install Git
  git config --global user.name "Your Name"
  git config --global user.email {username}@gmail.com

Next steps:

  mkdir projectname
  cd projectname
  git init
  touch README
  git add README
  git commit -m 'first commit'
  git remote add origin git@github.com:{username}/{projectname}.git
  git push origin master

【问题讨论】:

  • 看来初始提交无论出于何种原因都不起作用。 Git 日志帮助我查看提交是否有效。第二天我又试了一次,成功了。谢谢!
  • 如果你不添加任何文件、提交或运行 git init,你总是会遇到这类问题。因此,请始终运行git status 以查看是否一切正常。
  • 从现有代码创建分支到新创建的 git 存储库时出现类似错误。通过克隆 git 存储库解决了错误。
  • Error when “git push” to github 的可能重复项。

标签: git github


【解决方案1】:

我遇到了同样的问题,然后因为我没有真正添加我的项目文件而打了自己一巴掌。

git add -A
git commit -am "message"
git push origin master

【讨论】:

  • 是的,我尝试了以下方法,但我的解决方案是改用您的命令: git add * 正确的语法是: git add .
  • 做了同样的事情......天哪。谢谢!
【解决方案2】:

错误消息导致您的本地存储库中没有master 分支的结论。要么推送你的主要开发分支(git push origin my-local-master:master,它将在 github 上将其重命名为 master)或先提交。您不能推送完全空的存储库。

【讨论】:

  • 我遇到了“空存储库”的问题,因为 GitHub (beans.seartipy.com/2008/12/09/…) 引用的相关指南没有提到“git commit -m 'first commit'”命令。一旦我使用它,一切都很好!
  • 我刚刚忘记提交更改。
  • 当您说git push origin my-local-master:master 时,my-local-master 是什么意思?如果我有一个我想要推送的文件夹的 CSS-pix 名称
【解决方案3】:

我遇到了同样的问题。我删除了 .git 文件夹,然后按照以下命令进行操作

  1. $ git init
  2. $ git add .
  3. $ git remote add origin git@gitorious.org:project/project.git
  4. $ git commit -m "Initial version"
  5. $ git push origin master

【讨论】:

    【解决方案4】:

    我有同样的问题。它解决了我的问题。 如果你初始化你的 git 。你必须在终端上做

    1) git add .

    2)git commit -m "first commit"

    用于发送到 bitbucket

    3)git push -u origin --all # pushes up the repo and its refs for the first time

    【讨论】:

      【解决方案5】:

      我在创建我的第一个 Git 存储库时遇到了同样的问题。我在 Git 源远程创建中有错字 - 结果我没有大写存储库的名称。

       git remote add origin git@github.com:Odd-engine
      

      首先我删除了旧遥控器使用

      git remote rm origin
      

      然后我重新创建了来源,确保输入的来源名称与我的来源的拼写方式完全相同。

      git remote add origin git@github.com:Odd-Engine
      

      没有更多错误! :)

      【讨论】:

        【解决方案6】:

        我遇到了同样的错误,因为 Bombe 说我的配置中没有名为 master 的本地分支,尽管 git branch 确实列出了一个名为 master 的分支...

        要修复它,只需将其添加到您的 .git/config 中

        [branch "master"]
            remote = origin
            merge = refs/heads/master
        

        有点老套,但能胜任

        【讨论】:

          【解决方案7】:

          确保你在一个分支上,至少在 master 分支上

          类型:

          git branch
          

          你应该看到:

          ubuntu-user:~/git/turmeric-releng$ git 分支

          * (no branch)
          master
          

          然后输入:

          git checkout master
          

          那么您的所有更改都将适合主分支(或您选择的分支)

          【讨论】:

            【解决方案8】:
            error: failed to push some refs to 'git@github.com:{username}/{projectname}.git'
            

            除非您概括错误消息,否则看起来您确实将 git@github.com:{username}/{projectname}.git 作为远程 Git 存储库。您应该使用您的 GitHub 用户名填写 {username},并使用您的项目名称填写 {projectname}

            【讨论】:

              【解决方案9】:

              为了真正解决问题,我使用以下命令将所有文件暂存到提交。

              $ git add .
              $ git commit -m 'Your message here'
              $ git push origin master
              

              我遇到的问题是 git add 中的 -u 命令实际上并没有添加新文件,并且我的 git 安装不支持 git add -A 命令。因此,正如这个线程中提到的,我试图暂存的提交是空的。

              【讨论】:

              • 它对我有用!我尝试了太多命令,但没有任何改变……但这就是我的解决方案!
              【解决方案10】:

              看起来这个问题已经有很多答案了,但我会权衡一下我的,因为我还没有看到任何可以解决我遇到的问题的答案。

              我在一个全新的 github 存储库上也遇到了这个错误。事实证明,我从中推送的用户没有推送访问权限。出于某种原因,这会导致“错误:找不到存储库”错误,而不是某种访问错误。

              无论如何,我希望这对遇到同样问题的可怜人有所帮助。

              【讨论】:

                【解决方案11】:

                我解决了我的问题....

                不确定是什么问题,但使用 gitx 接口提交我的暂存文件,然后...

                $ git push origin master
                

                工作...

                我也遇到了同样的问题……

                在 bort 模板文件中创建了一个新文件夹...

                $ git commit -m 'first commit'
                
                $ git remote add origin git@github.com:eltonstewart/band-of-strangers.git
                
                $ git push origin master
                

                然后我得到同样的错误......

                错误:src refspec master 不匹配任何内容。
                致命:远端意外挂断
                错误:未能将一些参考推送到 'git@github.com:eltonstewart/band-of-strangers.git'

                【讨论】:

                  【解决方案12】:
                  cd  app 
                  
                  git init 
                  
                  git status 
                  
                  touch  test 
                  
                  git add . 
                  
                  git commit  -a  -m"message to log " 
                  
                  git commit  -a  -m "message to log" 
                  
                  git remote add origin 
                  
                   git remote add origin git@git.google.net:cherry 
                  
                  git push origin master:refs/heads/master
                  
                  git clone git@git.google.net:cherry test1
                  

                  【讨论】:

                    【解决方案13】:

                    我有同样的问题。我错误地在小写的机器中创建了目录。一旦改变了案例,问题就解决了(但浪费了我的 1.5 小时 :( ) 看看你的目录名和远程仓库名是一样的。

                    【讨论】:

                      【解决方案14】:

                      一分钟前有同样的问题,然后修复了它

                      在 github 中创建一个名为 wordpress 的存储库...

                      cd wordpress
                      git init
                      git add -A
                      git commit -am “WordPress 3.1.3″ or any message
                      git remote add origin git@github.com:{username}/wordpress.git
                      git push -u origin master
                      

                      这应该可以解决 refspec 问题

                      【讨论】:

                      • 感谢它为我工作..我能知道“git add”之间有什么区别吗?和“git add -A”
                      • 如果你在 v 2.x 上没有区别,只有当你在 1.x 上检查表以备将来参考时才重要:stackoverflow.com/a/26039014/640727
                      【解决方案15】:

                      这也可能发生,因为 github 最近将默认分支从“master”重命名为“main”(https://github.com/github/renaming),所以如果您刚刚在 github 上创建了一个新存储库,请使用 git push origin main 而不是 git push origin master

                      【讨论】:

                        【解决方案16】:

                        我错误地在 - 之后放了一个空格,所以我用 -m 而不是 -m 只是要寻找的东西。

                        【讨论】:

                          【解决方案17】:

                          我认为在旧版本的 git 中,你应该先提交至少一个文件,然后你可以再次“push origin master”。

                          【讨论】:

                            【解决方案18】:

                            太棒了.. 空目录的问题仅此而已。我通过在每个目录中创建一个二进制文件然后添加它们来解决我的问题。

                            【讨论】:

                              【解决方案19】:

                              初始添加和提交就像一个魅力。我想这只是理解 Git 在存储库中管理项目的方法的问题。

                              在那之后,我设法毫不费力地直接推送我的数据。

                              【讨论】:

                                【解决方案20】:

                                我刚遇到这个问题,似乎是我的not在默认提交消息上方添加了自定义提交消息引起的(我想,为什么要写“初始提交”,当它明确表示时在它下面的 Git 生成的文本中也是一样的东西)。

                                当我删除 .git 目录、为 Git 重新初始化项目目录、重新添加 GitHub 远程、将所有文件添加到新阶段、在自动生成的消息上方使用个人消息提交时问题解决了,并推送到 origin/master。

                                【讨论】:

                                  【解决方案21】:

                                  当您在 Github 上创建存储库时,它会将 README.md 文件添加到存储库中,并且由于该文件可能不在您的本地目录中,或者它可能具有不同的内容,所以 git push 会失败。 为了解决我所做的问题:

                                  git pull origin master
                                  git push origin master
                                  

                                  这一次它成功了,因为我有 README.md 文件。

                                  【讨论】:

                                    【解决方案22】:

                                    在第一次提交之前,尝试添加一些文件,例如 readme.txt。这将“强制”远程 repo 创建分支 master,以防不存在。它对我有用。

                                    【讨论】:

                                      【解决方案23】:

                                      这是一个非常古老的问题,但对于像我这样最终会来到这里的所有新人来说。 此解决方案仅适用于

                                      error: src refspec master does not match any.
                                      

                                      创建新仓库时出错

                                      你需要添加你的

                                      git config user.email "your email"
                                      git config user.name "name"
                                      

                                      仅在添加电子邮件和名称后将文件添加到 git 并提交

                                      git add .
                                      git commit -m "message"
                                      

                                      它会像魅力一样工作

                                      【讨论】:

                                        【解决方案24】:

                                        我也有这个错误,我提交了一个不推送空项目的承诺,就像很多人一样,但不起作用

                                        问题是 ssl,你放下一个

                                        git config --system http.sslverify false

                                        然后一切正常:)

                                        git push origin master

                                        【讨论】:

                                          【解决方案25】:

                                          我遇到了同样的问题/错误。我正在做git push -u origin master 而我只是做了git push origin master 并且它有效。

                                          【讨论】:

                                            【解决方案26】:

                                            转到控制面板 -> 管理您的凭据并删除 github 凭据(如果有)。

                                            【讨论】:

                                              【解决方案27】:

                                              碰到一个旧线程。

                                              如果您在 Github 上使用 Readme.gitignore 创建了一个存储库,您可能需要使用远程 master 重新定位本地 master。因为,如果您使用的是项目脚手架工具,例如 create-app,它会为您创建这些文件,并且远程 master 需要在您推送之前与您的本地同步。

                                              如果你在 Github 上创建一个空的仓库,那么你可以简单地推送。

                                              【讨论】:

                                                【解决方案28】:

                                                我遇到了同样的问题,一些用户已经回答了这个问题。在推送之前,您必须进行第一次提交。 现在,对于新用户,我创建了一系列简单的步骤。在此之前,您需要安装 git 并在命令行中运行:

                                                • git config user.email "你的邮箱"
                                                • git config user.name "name"

                                                创建远程仓库的步骤(我使用dropbox作为远程仓库):

                                                1. create a directory in Dropbox (or on your remote server)
                                                2. go to the Dropbox dir (remote server dir)
                                                3. type git command: git init --bare
                                                4. on your local drive create your local directory
                                                5. go to local directory
                                                6. type git command: git init
                                                7. add initial files, by typing git command:: git add <filename> 
                                                8. type git command: git commit -a -m "initial version" (if you don't commit you can't do the initial push
                                                9. type git command: git remote add name <path to Dropbox/remote server> 
                                                10. git push name brach (for first commit the branch should be master)
                                                

                                                【讨论】:

                                                  猜你喜欢
                                                  • 2013-03-02
                                                  • 2021-03-11
                                                  • 2016-04-07
                                                  • 1970-01-01
                                                  • 2018-08-02
                                                  • 2012-08-12
                                                  • 1970-01-01
                                                  • 1970-01-01
                                                  相关资源
                                                  最近更新 更多