Gitプッシュエラー '[リモート拒否] master -> master (ブランチは現在チェックアウトされています)' 質問する

Gitプッシュエラー '[リモート拒否] master -> master (ブランチは現在チェックアウトされています)' 質問する

昨日、クローンの作り方について質問を投稿しました。ギットリポジトリをマシンから別のマシンへ別のマシンから「git clone」するにはどうすればいいですか?

これで、ソース (192.168.1.2) から宛先 (192.168.1.1) に Git リポジトリを正常にクローンできるようになりました。

git commit -a -m "test"しかし、ファイル aと aを編集するとgit push、宛先 (192.168.1.1) で次のエラーが発生します。

git push                                                
[email protected]'s password: 
Counting objects: 21, done.
Compressing objects: 100% (11/11), done.
Writing objects: 100% (11/11), 1010 bytes, done.
Total 11 (delta 9), reused 0 (delta 0)
error: refusing to update checked out branch: refs/heads/master
error: By default, updating the current branch in a non-bare repository
error: is denied, because it will make the index and work tree inconsistent
error: with what you pushed, and will require 'git reset --hard' to match
error: the work tree to HEAD.
error: 
error: You can set 'receive.denyCurrentBranch' configuration variable to
error: 'ignore' or 'warn' in the remote repository to allow pushing into
error: its current branch; however, this is not recommended unless you
error: arranged to update its work tree to match what you pushed in some
error: other way.
error: 
error: To squelch this message and still keep the default behaviour, set
error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To git+ssh://[email protected]/media/LINUXDATA/working
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'git+ssh://[email protected]/media/LINUXDATA/working'

2 つの異なるバージョンの Git (リモートでは 1.7、ローカル マシンでは 1.5) を使用しています。これが原因でしょうか?

ベストアンサー1

このエラー メッセージはerror: refusing to update checked out branch: refs/heads/masterリモート リポジトリによって発行され、作業ディレクトリに現在チェックアウトされている別のコードを持つリモートの非ベア リポジトリにコードをプッシュしようとしていることを意味します。この問題を回避する最善の方法は、ベア リポジトリにのみプッシュすることです。この問題はベア リポジトリでは発生しません。

リモート リポジトリをベア リポジトリに変換するだけです (ベア リポジトリには作業コピーはなく、フォルダーには実際のリポジトリ データのみが含まれます)。

リモート リポジトリ フォルダーで次のコマンドを実行します。

git config --bool core.bare true

次に、そのフォルダー以外のすべてのファイルを削除します。その後、エラーなしでリモート リポジトリに対して.git実行できるようになります。git push

おすすめ記事