Pushing to a non-bare Git repository

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 receive.denyCurrentBranch:

  • 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 and warn will cause inconsistent issues. You need to execute git reset --hard manually later 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 executes git reset --hard later for you.


Set receive.denyCurrentBranch to ignore, warn or updateInstead (according to your needs) in the remote non-bare repository to allow pushing the current branch.

# Config receive.denyCurrentBranch to ignore in the remote repository
# The configuration is applied to only this respository.
$ git config receive.denyCurrentBranch ignore

# Config receive.denyCurrentBranch to updateInstead in the remote repository
$ git config receive.denyCurrentBranch updateInstead

Leave a Reply