昨日、Gitのリポジトリを自分のマシンから別のマシンにクローンする方法についての質問を投稿しました。 *[How can I 'git clone' from another machine?
現在、Gitリポジトリをコピー元(192.168.1.2)からコピー先(192.168.1.1)にクローンすることに成功しました。
しかし、ファイルを編集して、git commit -a -m "test"
と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)。それが原因の可能性はありますか?
私はちょうどGitを学び始めた時に同じエラーが出ました。他の回答の中には、明らかにGitを初めて使う人向けではないものもありますね
(とにかく、あなたには2つのリポジトリがあって、1つは最初に作ったオリジナル、もう1つは今作ったばかりの作業用です。
今、あなたは作業用のリポジトリにいて、「master」ブランチを使っています。しかし、あなたは元のリポジトリで、同じ「master」ブランチに「ログイン」しています。元のリポジトリに「ログイン」しているので、元のリポジトリで作業をしていて何か失敗してしまうのではないかとGitは心配しています。そこで、元のリポジトリに戻って "git checkout someotherbranch" を行う必要があります。これで、問題なくプッシュできるようになりました。
お役に立てれば幸いです。
エラーメッセージには、何が起こったのかが書かれています。最近のGitでは、ブランチがチェックアウトされている場合はプッシュによるブランチの更新を拒否するようになっています。
裸のリポジトリではないふたつのリポジトリ間で作業する最も簡単な方法は、次のいずれかです。
別のブランチ (インポートブランチ) にプッシュし、そのブランチをリモートマシンの master ブランチにマージする。
このような制限があるのは、プッシュ操作はリモートの Git リポジトリに対してのみ行われ、インデックスや作業ツリーにはアクセスできないからです。そのため、もし許可されていれば、チェックアウトしたブランチをプッシュすると、リモートリポジトリのインデックスや作業ツリーと矛盾した HEAD
**に変更されてしまいます。
これにより、プッシュされた変更をすべて元に戻すような変更を誤ってコミットすることが非常に容易になります また、コミットされていないローカルの変更と、新しい HEAD
とインデックスや作業ツリーの違いを区別することが非常に困難になります。