我多次看到这个问题了。我已经尝试了每一个答案。
其中没有一个确实有效。自从写完以来,git中的某些内容可能会发生变化吗?
要明确:我有本地结账,我想在远程办理类似的结账。我知道我可以使用scp -r . ssh://remote/somefolder
但是scp非常慢,所以我更喜欢使用git。
一些答案说
$ mkdir somefolder
$ cd somefolder
$ git init
$ git push --mirror ssh://remote/somefolder
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'.
其他答案说
$ mkdir somefolder
$ cd somefolder
$ git init --bare
这失败了。现在somefolder
充满了git文件而不是.git
文件夹
好吧,让我猜猜
$ mkdir somefolder
$ cd somefolder
$ git init --bare .git
嘿我在.git
somefolder
个文件夹
让我们推
$ git push --mirror ssh://remote/somefolder/
$ cd somefolder
$ git status
fatal: This operation must be run in a work tree
我想回答的问题是,我如何将本地仓库推送到远程服务器,以便在远程服务器上它的行为与我克隆回购的完全一样。
换句话说,如果我能做到这一点
git clone ssh:// local / somefolder /
我不能这样做,因为本地没有公共IP地址服务ssh。所以相反,我想推动它。当它完成远程应该有
somefolder
|
+- .git
并且应该检查主分支,就像我克隆的那样。
答案 0 :(得分:1)
这个怎么样:
在遥控器上:
$ mkdir somefolder
$ cd somefolder
$ git init --bare
on local
$ git push ssh://remote/somefolder/
再次遥控,只是第一次
$ mkdir someotherfolder
$ cd someotherfolder
$ git clone somefolder .
再次遥控,后续通话 $ git pull
我认为您可以在hooks
的后续通话中自动执行此操作答案 1 :(得分:1)
如果您完全按照错误消息中的说明操作该怎么办:
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.
在远程非裸存储库中运行它:
git config receive.denyCurrentBranch ignore
但警告是有原因的;这将与远程工作树的编辑相互影响很小。如果这样做,请不要直接在遥控器上编辑文件而不提交它们!