【问题标题】:Failed to pushing files into newly created git repo无法将文件推送到新创建的 git repo
【发布时间】:2012-05-24 15:16:15
【问题描述】:

也许是一个重复的问题,虽然我试图从现有问题中找出答案但失败了。

我使用命令在服务器上创建了一个 git repo:

mkdir gitrepo
cd gitrepo
git init

然后我尝试从另一台机器将文件推送到这个 repo 但失败了。

git init
git clone user@server:~/gitrepo/.git
cd gitrepo
touch test
git add test
git commit -a

到目前为止,没有发生错误。当我尝试将更改推送到服务器时,出现以下错误:

>git push
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to 'user@server:~/gitrepo/.git'

以前有人遇到过这个问题吗?

我发现一个博客很好地解释了非裸仓库和裸仓库之间的区别。 http://www.bitflop.com/document/111 遇到同样问题的可以参考这里。

【问题讨论】:

  • 也许你应该指定一个分支,比如'master'。
  • 我试过这个“git push master”,得到“致命:'master'似乎不是 git 存储库。致命:远程端意外挂断”。当前我在 master 分支上

标签: git git-push


【解决方案1】:

git push [remote-name] [branch-name]。例如git push origin master

【讨论】:

    【解决方案2】:

    在第一台机器上,您创建了一个非裸存储库,或者一个具有工作副本的存储库。推送到非裸仓库可能会有点令人兴奋,因此请确保这确实是您想要的。

    在第二台机器上,您在当前目录 (git init) 中创建了一个新存储库,然后将 gitrepo 克隆到子目录中作为第二个存储库。同样,没关系,只要确保它是你想要的。

    以下是第一台机器上的裸仓库和第二台机器上的一个仓库的工作方式:

    第一台机器:

    git init --bare gitrepo.git
    

    第二台机器:

    git clone user@server:~/gitrepo.git
    cd gitrepo
    touch test
    git add test
    git commit -a
    
    # '-u' tells git to track the remote master branch with your local master branch
    git push -u origin master
    

    【讨论】:

      【解决方案3】:

      参考“Why can't I push to this bare repository?”

      尝试做:git push --set-upstream origin master

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-06-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-03-10
        • 2015-06-25
        • 1970-01-01
        • 2020-04-21
        相关资源
        最近更新 更多