[英]Can't push to remote repository even though remote is set to bare
我一直在寻找解决此问题的方法,但似乎找不到适合我的方法。 所以我想我会问你。
我最近学习了如何使用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很陌生,所以很可能我做了一些愚蠢的事情。 有人看到我哪里出问题了吗?
问题:您要将内容推送到非裸服务器存储库(该文件具有作为工作副本签出的文件)。 从技术上讲这是可能的,但这不是“常规”设置。 首先,请针对您当前的情况为您提供“解决方案”:
a)在您的服务器上,将git repo初始化为'bare',即
git config core.bare true
这样,您可以使用允许的git协议(包括ssh)之一从其他计算机访问此文件。
或b)在服务器计算机上:
git config receive.denyCurrentBranch ignore
或(git v2.3 +)c)
git config --local receive.denyCurrentBranch updateInstead
请记住,当您从笔记本电脑上推送并同时提交到服务器上时,上述选项会给您带来麻烦。
更好的解决方案是在其他位置(甚至在同一服务器上)创建一个单独的git repo,您的Web服务器帐户和便携式计算机可以访问该仓库。 然后在您的Web服务器和笔记本电脑中克隆此仓库。 例:
</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>
您的工作流程将如下所示:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.