繁体   English   中英

如何将本地git文件夹(repo)克隆到远程服务器

[英]How do I clone a local git folder(repo) to a remote server

我看到这个问题问了很多遍。 我已经尝试了所有答案。

实际上,没有一个人真正起作用。 自编写以来,git中的某些内容可能发生了变化?

需要说明的是:我有一个本地结帐,我想在远程进行类似的结帐。 我知道我可以使用scp -r . ssh://remote/somefolder 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://本地/ somefolder /

我不能这样做,因为本地没有提供ssh的公共IP地址。 因此,我想推动它。 完成后,遥控器应具备

somefolder
|
+- .git

并且应该检出master分支,就像克隆了克隆一样。

这个怎么样:

在远程:

$ mkdir somefolder
$ cd somefolder
$ git init --bare

在本地

$ git push ssh://remote/somefolder/

再次在远程,只有第一次

$ mkdir someotherfolder
$ cd someotherfolder
$ git clone somefolder .

再次在远程上,后续调用$ git pull

我认为您可以在随后的带有钩子的调用中自动执行此操作

如果您完全按照错误消息中的说明进行操作,该怎么办:

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

但是,出现警告是有原因的。 这将无法与对远程工作树的编辑进行很好的交互。 如果这样做,切勿在不提交的情况下直接在远程文件上编辑文件!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM