[英]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.