无法进入git仓库

car*_*rds 42 git

这是我到目前为止所做的,我会说这个程序适用于Ubuntu 9.10,它可能有不同版本的git.

server: mkdir ~/git

local: scp -r /../project name@url.com:~/git/
server: cd git
        cd project
        git init 
        git add .
        git commit -a -m "initial"

local: git clone name@url.com:/../git/project /home/name/project
   cd project
   capify .  (from the ruby gem capistrano)
   git add .
   git commit -a -m "capified"
   git push
Run Code Online (Sandbox Code Playgroud)

当我尝试推出时,我收到此错误消息:

   remote: error: refusing to update checked out branch: refs/heads/master
   remote: error: By default, updating the current branch in a non-bare repository
   remote: error: is denied, because it will make the index and work tree inconsistent
   remote: error: with what you pushed, and will require 'git reset --hard' to match
   remote: error: the work tree to HEAD.
   remote: error: 
   remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
   remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
   remote: error: its current branch; however, this is not recommended unless you
   remote: error: arranged to update its work tree to match what you pushed in some
   remote: error: other way.
   remote: error: 
   remote: error: To squelch this message and still keep the default behaviour, set
   remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
   To ...
   ! [remote rejected] master -> master (branch is currently checked out)
   error: failed to push some refs to
Run Code Online (Sandbox Code Playgroud)

Hav*_*veF 75

在服务器端,执行以下操作:

git config receive.denyCurrentBranch ignore
Run Code Online (Sandbox Code Playgroud)

然后你可以在当地推.

  • 对于更新版本的git,最好使用`updateInstead`选项而不是`ignore`; 见VonC的答案. (4认同)

Von*_*onC 46

现在可以推出非裸机回购(Git 2.3.0 2015年2月).
当你推动目前在远程仓库检查的分支时,它是可能的!

提交1404bcb约翰内斯Schindelin( )dscho:

receive-pack:添加另一个选项 receive.denyCurrentBranch

在工作目录之间进行同步时,通过" push而不是" 更新当前分支可能很方便pull,例如从VM内部推送修复程序时,或者在用户计算机上进行修复时(开发人员不在此处)安装ssh守护进程的自由,更不用说知道用户的密码了.

这个补丁不再需要常见的解决方法 - 推入临时分支然后在另一台机器上合并.

新选项是:

updateInstead
Run Code Online (Sandbox Code Playgroud)

相应地更新工作树,但如果有任何未提交的更改,则拒绝这样做.

那是:

git config receive.denyCurrentBranch updateInstead
Run Code Online (Sandbox Code Playgroud)


Dip*_*ick 7

正如我在这篇文章中指出的类似heroku的git设置? 推进工作存储库有点危险,因为推进时没有考虑任何正在进行的工作,并且随后很容易丢失任何未提交的更改(基本上工作的HEAD可能与工作分支HEAD不一致).Git现在有一个警告告诉你这个 - 血腥,细节在以下链接:

git推送到非裸存储库

建议您发布的存储库应该是一个没有签出树的裸仓库.裸回购是使用"git clone --bare"选项创建的.


nil*_*lsi 5

由于您git init在服务器上运行,因此创建了可正常使用的目录,但我认为您想创建一个裸仓库

当您想在开发机器上本地添加,编辑和删除项目中的文件时,请使用工作目录。

当您要共享项目时,git init --bare project.git在服务器上建立一个裸存储库,然后将其克隆到您的计算机上,便可以推送到它。

如果您现在不想创建新项目,则可以通过以下方式将项目克隆到新的裸仓库中 git clone --bare project new-bare-project.git


小智 5

请尝试以下命令:

git config receive.denyCurrentBranch warn
Run Code Online (Sandbox Code Playgroud)