By default, pushing a branch to a non-bare Git repository in which the branch is currently checked out is denied. The reason is it will cause inconsistent issue between the working tree (also the index) and the pushed HEAD. Through setting
receive.denyCurrentBranch option, you can able to do such a push.
Errors when pushing the current branch to a non-bare Git repository
$ git push master Counting objects: 4, done. Delta compression using up to 8 threads. Compressing objects: 100% (4/4), done. Writing objects: 100% (4/4), 3.63 KiB | 0 bytes/s, done. Total 4 (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. ...
The available values for
- refuse or true, refuse the push. It is the default value.
- ignore or false, allow the push.
- warn, allow the push but give a warning message to the client.
- updateInstead, allow the push and update the current branch in the remote repository.
The last three values allow the push, but
ignore will case inconsistent issues. You need to execute
git reset --hard to make the index and working directory match the pushed HEAD in the remote repository. The effect of
updateInstead looks like it allows the push and execute
git reset --hard later for you.
updateInstead in the remote non-bare repository to allow pushing the current branch.
# Config receive.denyCurrentBranch to ignore in the remote repository $ git config --local receive.denyCurrentBranch ignore # Config receive.denyCurrentBranch to updateInstead in the remote repository $ git config --local receive.denyCurrentBranch updateInstead