[英]git push to remote master branch
我有一個遠程和本地git存儲庫。
本地存儲庫是從遠程克隆的。
當我修改本地存儲庫並提交到master分支時。
然后我運行“ 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:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable t
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing int
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 som
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, se
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
我將遠程存儲庫中的另一個分支“ git checkout -b current”。
在我的本地存儲庫中,我運行“ git push”,然后成功。
但是本地修改只能推送到遠程主分支。
然后,我應該在遠程存儲庫中運行“ git merge master”以進行更改。
我是git的新手。
我做錯了嗎?
遠程存儲庫不是裸存儲庫,並且已檢出主數據庫。 而且,默認情況下,git不允許您推送到非裸倉庫的已簽出分支。
理想情況下,應將您要推送到的遠程存儲庫設置為裸存儲庫( git init --bare
)。
manojlds的回答是正確的,但是這可能有助於了解遠程回購的目的。
一個很好的確認是,您可以將“裸”存儲庫用於備份/協作目的,以便“推向生產”,然后您可以在部署服務器上設置一個單獨的存儲庫,並從裸存儲庫中克隆該存儲庫。 然后,在裸倉庫上,您可以放置一個“后接收掛鈎”,這使部署倉庫進行拉動。
我敢肯定有關於如何執行此操作的指南...我自己追蹤了一次:)
當我不熟悉github時,我的導師給了我這個遵循的經驗法則:
在本地修改您的代碼。 當需要提交時,請執行以下操作:
git pull
(將遠程回購的內部引用標頭同步到本地存儲庫非常重要) git push
來保存對代碼的本地更改,這些更改首先要提交。 顛覆可能會很痛苦,但是保持同步非常重要。 這些規則對我使用github維護子版本很有幫助。 希望這會有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.