non-bare で現在選択中のリポジトリに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: 

これは以下をignoreの設定をするとこで弾かなくできます。

git config receive.denyCurrentBranch ignore 

何かリモート先の自動スクリプトか何かでうまくgit pushできないことがあると、リモートのファイルの元の状態と更新後の状態とで差分(更新後の状態から、元の状態に変更したような状況)がでる時があるので、それはgit reset --hardで更新後の状態に戻しましょう。

ちなみにこれはpost-receiveフックを使うと自動化できるので、権限があるなら設定しておくと便利です。post-receiveファイルはこのような感じになります。

#!/bin/sh

cd ;
git --git-dir=.git reset --hard

実行権限も与えておきます。

chmod +x .git/hooks/post-receive

JavaScript で飯食べたい歴約 5 年、 純( nju33 ) によるノートサイトです。

このサイトではドリンク代や奨学金返済の為、広告などを貼らせて頂いてますがご了承ください。

Change Log