昨天,我發佈了一個有關如何將Git存儲庫從個人一臺計算機克隆到另外一臺計算機的問題 , 如何從另外一臺計算機「 git clone」? 。 git
如今,我能夠成功地將Git存儲庫從源(192.168.1.2)克隆到目標(192.168.1.1)了。 web
可是,當我對文件, git commit -a -m "test"
和git push
,我在目的地(192.168.1.1)上收到此錯誤: 服務器
git push hap@192.168.1.2's password: Counting objects: 21, done. Compressing objects: 100% (11/11), done. Writing objects: 100% (11/11), 1010 bytes, done. Total 11 (delta 9), reused 0 (delta 0) error: refusing to update checked out branch: refs/heads/master error: By default, updating the current branch in a non-bare repository error: is denied, because it will make the index and work tree inconsistent error: with what you pushed, and will require 'git reset --hard' to match error: the work tree to HEAD. error: error: You can set 'receive.denyCurrentBranch' configuration variable to error: 'ignore' or 'warn' in the remote repository to allow pushing into error: its current branch; however, this is not recommended unless you error: arranged to update its work tree to match what you pushed in some error: other way. error: error: To squelch this message and still keep the default behaviour, set error: 'receive.denyCurrentBranch' configuration variable to 'refuse'. To git+ssh://hap@192.168.1.2/media/LINUXDATA/working ! [remote rejected] master -> master (branch is currently checked out) error: failed to push some refs to 'git+ssh://hap@192.168.1.2/media/LINUXDATA/working'
我正在使用兩種不一樣的Git版本(遠程版本爲1.7,本地計算機版本爲1.5)。 那多是緣由嗎? less
使用Git同步Android手機和筆記本電腦上的存儲庫時,我遇到了一樣的問題。 對我來講,解決方案是執行拉動,而不是像@CharlesBailey建議的那樣進行推進。 ssh
Android存儲庫上的git push origin master
對於我失敗,並顯示與@ hap497相同的錯誤消息,這是因爲推送到存儲庫+工做副本的裸機檢出。 post
筆記本電腦存儲庫上的git pull droid master
和work-copy對我有用。 固然,您以前須要運行git remote add droid /media/KINGSTON4GB/notes_repo/
。 測試
您能夠經過如下測試來查看bare
服務器的工做方式: 網站
想象一下,您有一個工做站和一個託管有實時站點的服務器,而且您想不時更新此站點(這也適用於兩個開發人員經過一個裸露的中間人來回發送其工做的狀況)。 ui
在本地計算機上建立一些目錄並cd
進入該目錄,而後執行如下命令: this
# initialization git init --bare server/.git git clone server content git clone server local
server
目錄(請注意最後的.git)。 該目錄僅用做存儲庫文件的容器。 content
目錄。 這是您的現場/生產目錄,將由您的服務器軟件提供服務。 如今這是基本的工做流程:
輸入local
目錄,建立一些文件並提交。 最後將它們推送到服務器:
# create crazy stuff git commit -av git push origin master
如今進入content
目錄並更新服務器的內容:
git pull
重複1-2。 這裏的content
多是另外一個也能夠推送到服務器的開發人員,也多是local
開發人員,您能夠從他那裏獲取。
最好的方法是:
mkdir ..../remote cd ..../remote git clone --bare .../currentrepo/
這將克隆存儲庫,但不會在.../remote
建立任何工做副本。 若是查看遠程目錄,將會看到一個建立的目錄,名爲currentrepo.git
,這多是您想要的。
而後從您本地的Git存儲庫中:
git remote add remoterepo ..../remote/currentrepo.git
進行更改後,您能夠:
git push remoterepo master
我不得不在現有的裸倉庫中從新運行git --init
,這已經在裸倉庫樹中建立了一個.git
目錄-我意識到在那裏輸入git status
後。 我刪除了,一切都很好:)
(全部這些答案都是不錯的,但就我而言,這是徹底不一樣的(據我所知),如前所述。)
經過一些設置步驟,您可使用單線輕鬆將更改部署到您的網站
git push production
這很簡單,並且您沒必要登陸到遠程服務器便可執行拉取或其餘任何操做。 請注意,若是您不將生產結賬用做工做分支,這將最有效! (OP在稍微不一樣的上下文中工做,我認爲@Robert Gould的解決方案很好地解決了該問題。此解決方案更適合於部署到遠程服務器。)
首先,您須要在Webroot以外的服務器上的某個地方創建一個裸倉庫。
mkdir mywebsite.git cd mywebsite.git git init --bare
而後建立文件hooks/post-receive
:
#!/bin/sh GIT_WORK_TREE=/path/to/webroot/of/mywebsite git checkout -f
並使文件可執行:
chmod +x hooks/post-receive
在您的本地計算機上,
git remote add production git@myserver.com:mywebsite.git git push production +master:refs/heads/master
能夠了,好了! 如今,未來您可使用git push production
來部署您的更改!
此解決方案的信譽歸功於http://sebduggan.com/blog/deploy-your-website-changes-using-git/ 。 在此處查找有關發生的狀況的更詳細說明。