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