git main branch 提交遠程倉庫失敗

原文鏈接: http://cpbest.blog.163.com/blog/static/4124151920125292010825/

通常在用git clone了remote端(服務器)的git倉庫後,再進行了自己一系列修改後,會將自己測試後穩定的狀態push到remote端,以更新源倉庫,使 其他人在pull的時候得到自己的修改。但是在git push的時候會經常出現如下的錯誤提示。


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: 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: To squelch this message and still keep the default behaviour, set 

remote: error: ‘receive.denyCurrentBranch’ configuration variable to ‘refuse’.


根據上面所報的信息,它的意思就是默認情況下,git不允許用push操作更新non-bare的倉庫,因爲這樣的操作會導致remote倉庫的索引 (index)和工作樹(work tree)與你push的不一致,此時需要通過‘git reset –hard’操作來使得工作樹與HEAD索引相匹配。 可以通過在remote端,設置git的配置文件(.git/config),在其中添加如下內容:

 [receive] 

    denyCurrentBranch = false

這樣就可以通過git push提交自己的穩定更新,要想在push後在remote端看到更新的效果,執行git reset --hard即可。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章