Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 即使remote设置为bare,也无法推送到远程存储库_Git - Fatal编程技术网

Git 即使remote设置为bare,也无法推送到远程存储库

Git 即使remote设置为bare,也无法推送到远程存储库,git,Git,我一直在四处寻找如何解决这个问题,但似乎找不到任何适合我的方法。所以我想我应该问你 我最近学习了如何使用git进行源代码控制,并决定开始将其用于我已经构建的网站。我拥有的服务器不是我自己的网站。从arvixe购买服务器空间时已经安装了git。我通过ssh进入我的主文件夹并运行 git init 然后,我想将文件夹中已有的所有文件添加到git,因此我运行了: git add . 然后将其提交: git commit . 我希望能够从笔记本电脑推送到服务器,因此我这样做是为了获得一个空存储库:

我一直在四处寻找如何解决这个问题,但似乎找不到任何适合我的方法。所以我想我应该问你

我最近学习了如何使用git进行源代码控制,并决定开始将其用于我已经构建的网站。我拥有的服务器不是我自己的网站。从arvixe购买服务器空间时已经安装了git。我通过ssh进入我的主文件夹并运行

git init
然后,我想将文件夹中已有的所有文件添加到git,因此我运行了:

git add .
然后将其提交:

git commit .
我希望能够从笔记本电脑推送到服务器,因此我这样做是为了获得一个空存储库:

git init --bare

我在谷歌上搜索了这个问题,发现它在其他情况下也有效。在此之前,我尝试通过ssh签出一个虚拟分支,但当我这样做时,我从笔记本电脑推送到服务器实际上改变了任何东西

在此之后,我通过ssh和sourcetree将存储库克隆到我的笔记本电脑上。当我在笔记本电脑上进行更改并尝试将其推送到远程回购时,我会收到以下错误消息:

stdin: is not a tty

/etc/bashrc: line 100: $HISTFILE: ambiguous redirect

remote: error: refusing to update checked out branch: refs/heads/master[K
remote: error: By default, updating the current branch in a non-bare repository[K
remote: error: is denied, because it will make the index and work tree inconsistent[K
remote: error: with what you pushed, and will require 'git reset --hard' to match[K

remote: error: the work tree to HEAD.[K
remote: error: [K
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to[K
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into[K
remote: error: its current branch; however, this is not recommended unless you[K
remote: error: arranged to update its work tree to match what you pushed in some[K
remote: error: other way.[K
remote: error: [K
remote: error: To squelch this message and still keep the default behaviour, set[K
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.[K
To ssh://ihlenfmt@laurieihlenfield.com/home/ihlenfmt

 ! [remote rejected] master -> master (branch is currently checked out)

我对git很陌生,所以很可能我做了一些愚蠢的事情。有人看到我哪里出错了吗?

问题是:您想将内容推送到非裸服务器repo,该服务器将文件签出为工作副本。从技术上讲,这是可能的,但这不是一个正常的设置。我将首先为您解决当前的问题: 要么:

在服务器上,将git repo初始化为“裸”,即

git config core.bare true
通过这种方式,您可以使用一种允许的git协议(包括ssh)从其他机器访问它

或服务器计算机上的b:

git config receive.denyCurrentBranch ignore
或GitV2.3+c

git config --local receive.denyCurrentBranch updateInstead
请记住,当您从笔记本电脑上推送并同时在服务器上提交时,上述选项将给您带来问题

更好的解决方案是在其他地方创建一个单独的git回购协议,即使在同一台服务器上,您的web服务器帐户和笔记本电脑也可以访问该协议。然后在Web服务器和笔记本电脑中克隆此repo。例如:

</home/user/some-dir-accessible-via-ssh>$ git init . --bare
</your-webserver-root>$ git init . #(not bare)
</your-webserver-root>$ git commit #(etc)
</your-webserver-root>$ git push </home/user/some-dir-accessible-via-ssh> master
如果一切顺利

</your-webserver-root>$ git remote add origin </home/user/some-dir-accessible-via-ssh>
在笔记本电脑上

$git clone <ssh://user@serverip/home/user/some-dir-accessible-via-ssh>
您的工作流程如下所示:

在笔记本电脑上工作,拉,然后推到服务器。 转到sever,从原点拉 在服务器上进行更改。推回原点 等
在此之前,我尝试通过ssh签出一个虚拟分支,但当我这样做时,我从笔记本电脑推送到服务器实际上改变了任何东西。这是否意味着您在现有存储库中运行了git init-bare?现有存储库不会以这种方式暴露。相反,在新目录中运行该命令。同意@Chris,或者您可以通过删除除.git之外的所有文件和目录,将.git的所有内容移动到项目的根目录,将非裸repo转换为裸repo,在配置中删除.git并将core.bare设置为true。有关详细信息,请参阅@jörg-w-mittagI给出的答案。我会尝试一下!非常感谢。