事象
Gitの勉強でSourceTreeにてローカルにリポジトリを作成し、それを更にローカルの別領域にクローンした。
その後、コミットが終わったのでPushをした際に以下のようなエラーが起きた
エラー内容
git -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree push -v --tags origin refs/heads/master:refs/heads/master
Pushing to 〜
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: is denied, because it will make the index and work tree inconsistent
remote: with what you pushed, and will require 'git reset --hard' to match
remote: the work tree to HEAD.
remote:
remote: You can set the 'receive.denyCurrentBranch' configuration variable
remote: to 'ignore' or 'warn' in the remote repository to allow pushing into
remote: its current branch; however, this is not recommended unless you
remote: arranged to update its work tree to match what you pushed in some
remote: other way.
remote:
remote: To squelch this message and still keep the default behaviour, set
remote: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To 〜
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 〜
Completed with errors, see above
原因
Githubなどのリポジトリはリモートリポジトリでありベアリポジトリ(更新用)、リモートリポジトリからフォークしたリポジトリやSourceTreeなどで作成したローカルリポジトリはノンベアリポジトリ (作業用)であり、ノンベアリポジトリからノンベアリポジトリにPushすることはできないため、エラーが起きていた。
ノンベアリポジトリをベアリポジトリに変更するコマンドなどもネット上にあったが、SourceTreeからリモートリポジトリを作成する方法は無さそうであったため、素直にリモートリポジトリはGithubやローカルにGitblitを構築して利用することにした。