I'm on mac os x, enabled ssh. I was trying to push local change to remote repo. I simulated remote repo locally like this: Create the remote repo
$cd ~/learn
$mkdir gittest
$cd gittest/
$git init
$git config --global user.name "username"
$git config --global user.email "useremail"
$touch readme
$git add readme
$git commit -m "empty"
OK, everything fine, then in another directory, I did:
$cd ~/learn/client
$git clone trosky@localhost:/Users/trosky/learn/gittest
$cd gittest
$vi readme(add one line)
$git add .
$git commit -m "add line"
$git push origin master:refs/heads/master
It failed and git says:
$git push origin master:refs/heads/master
Total 0 (delta 0), reused 0 (delta 0)
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:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To x@localhost:/Users/trosky/gittest
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'x@localhost:/Users/trosky/learn/gittest'
Does this indicate that, either remote repo or local client side has any problem? How to fix it?
The error message is telling you that (the remote you are trying to push to is not a bare repo and in fact that...) the branch you're trying to push to is checked out in that repository. By default it is not allowed to push to a non-bare repo, and not allowed to push to a checked out branch. But you can configure the remote system to allow it by making the
git config
changes on the remote system that the error message gives you.I suspect that if you'd googled the error message, you would have found many existing websites giving this same answer.