2015-09-06 97 views
0

我一直在四處搜尋以找出如何解決此問題,但似乎無法找到適合我的任何內容。所以我想我會問你。即使遠程設置爲裸設備,無法推送到遠程存儲庫

我最近學會了如何使用git進行源代碼控制,並決定我想開始將它用於我已經構建的網站。我有網站的服務器(不是我自己的,從arvixe購買服務器空間)已經安裝了git。我開始(通過SSH)將我的主文件夾和運行

git init 

設置,然後我想添加的所有我已經有文件夾中的文件與git所以我跑:

git add . 

然後提交它們:

git commit . 

我希望能夠從我的筆記本電腦推到服務器,所以我這樣做是爲了得到一個純倉庫:

git init --bare 

(我在google搜索了這個問題後發現它在其他情況下有效。在此之前,我嘗試通過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://[email protected]/home/ihlenfmt 

! [remote rejected] master -> master (branch is currently checked out) 

我很新與git所以它極有可能我做了一些愚蠢的事。任何人都能看到我出錯的地方嗎?

+1

「這個我試過檢查出通過ssh的虛擬分支,但是當我這樣做什麼,我從我的筆記本電腦推到了服務器實際上改變任何東西。之前」這是否意味着你在現有的倉庫中運行'git init --bare'?現有的存儲庫將不能進行裸這種方式。相反,請在新目錄中運行該命令。 – Chris

+0

同意@克里斯,或者您可以通過刪除所有文件和目錄(除'.git'),移動.git'的'所有內容到項目的根把非裸露回購成裸露的回購協議,刪除' .git'並設置'core.bare'爲'真'的配置(詳見這個答案http://stackoverflow.com/a/2200662/1157272通過@約爾格-W-午報) – joran

回答

0

問題:您想將內容推送到非裸露的服務器回購站(將文件簽出爲工作副本)。從技術上講,這是可能的,但這不是一個「正常」的設置。我會給你一個「修復」您目前的情況第一: 或者:

一)您的服務器上,初始化混帳回購協議爲「裸」,即

git config core.bare true 

這樣,您就可以訪問此從其他機器使用其中一個允許的git協議(包括ssh)。

或b)在服務器計算機上:

git config receive.denyCurrentBranch ignore 

OR(GIT V2.3 +)C)

git config --local receive.denyCurrentBranch updateInstead 

請記住,以上選項會造成問題的道路當你從你的筆記本電腦推送並同時在服務器上提交時。

更好的解決方案是在其他地方(甚至在同一臺服務器上)創建一個單獨的git倉庫,可以通過您的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://[email protected]/home/user/some-dir-accessible-via-ssh> 

您的工作流程是這樣的:在你的筆記本電腦

  • 工作,拉,然後推送到服務器。
  • 轉到服務器,從產地拉
  • 使服務器上進行更改。推到原點
+0

我給這一試!謝謝! – mtihlenfield

+0

這工作得很好!謝謝! – mtihlenfield

相關問題