2013-06-24 55 views
2

這是我到目前爲止已經完成:推的Git收到「錯誤:拒絕以更新簽出分支」

我成功地克隆了我的遠程回購到一個新的目錄,我的本地機器上。

然後我編輯了一個工作副本中的文件,提交了它,並試圖將它推送到遠程回購。這裏是我得到的錯誤:

$ git push origin master 
[email protected]'s password: 
Counting objects: 9, done. 
Delta compression using up to 4 threads. 
Compressing objects: 100% (5/5), done. 
Writing objects: 100% (5/5), 456 bytes | 0 bytes/s, done. 
Total 5 (delta 4), reused 0 (delta 0) 
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 inconsist 
ent 
remote: error: with what you pushed, and will require 'git reset --hard' to matc 
h 
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'. 
To [email protected]:/var/www/html 
! [remote rejected] master -> master (branch is currently checked out) 
error: failed to push some refs to '[email protected]:/var/www/html' 

你對我如何解決這個問題有任何想法嗎?謝謝。

這裏是我的本地的Git cofiguration:

$ git config -l 
core.symlinks=false 
core.autocrlf=true 
color.diff=auto 
color.status=auto 
color.branch=auto 
color.interactive=true 
pack.packsizelimit=2g 
help.format=html 
http.sslcainfo=/bin/curl-ca-bundle.crt 
sendemail.smtpserver=/bin/msmtp.exe 
diff.astextplain.textconv=astextplain 
rebase.autosquash=true 
merge.tool=tortoisemerge 
gui.recentrepo=C:/Users/Chris/Dev/Projects/html 
[email protected] 
user.name=CBarnhill 
core.repositoryformatversion=0 
core.filemode=false 
core.bare=false 
core.logallrefupdates=true 
core.symlinks=false 
core.ignorecase=true 
core.hidedotfiles=dotGitOnly 
[email protected]:var/www/html 
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/* 
branch.master.remote=origin 
branch.master.merge=refs/heads/master 
user.name=Chris Barnhill 
[email protected] 
gui.wmstate=normal 
gui.geometry=887x427+26+26 171 192 
+0

Git問題非常歡迎,因此:) – StuartLC

+0

可能重複的[Git推送錯誤'\ [遠程拒絕\]主 - >主(分支目前檢出)'](http://stackoverflow.com/questions/2816369/git-push-error-remote-rejected-master-master-branch-is-currently-checked) – kostix

回答

4

遠程主分支顯然處於非裸狀態,這意味着任何推入該分支的人都會覆蓋已簽出的工作副本(對HEAD的引用)的現有狀態。這不是一件好事。

爲了解決這個問題,你既可以使用裸存儲庫作爲「公用」回購(與「git的初始化--bare」做到這一點),或設有分公司工作:

git的結帳-b myBranch

在這個分支上做你的工作並提交。然後用'git push origin myBranch'推動你的分支,而不必破壞任何東西。之後,您在遠程倉庫中的分支可以合併或重新組裝成主倉。

+0

我創建了一個名爲'CBarnhill'的遠程分支並提交了文件更改。我嘗試了下面的push命令,但得到了以下錯誤: $ git push origin CBarnhill [email protected]的密碼: 致命︰'var/www/html'似乎不是git存儲庫 致命:無法從遠程存儲庫讀取。 請確保您擁有正確的訪問權限 並存在存儲庫。 –

+0

關於使用裸遙控回購,這不是一個選項,因爲遠程回購包含生產代碼。我無法刪除它。 –

+0

你能否就我的git問題向我提供任何進一步的建議? –

3

不是消息在漫長的描述不夠清楚嗎?

你可以做三件事情:

  • 使原有的回購裸露,並推動無論你是喜歡
  • 設置配置的receive.denyCurrentBranch的建議,讓推向簽出的分支,並採取關心差異的
  • 簽出不同的分支目標回購

甚至可能力推會的工作,我不建議。

+0

+1對於很好的RTFM – eckes