Take the tour ×

Hi I have solved some merge conflicts, committed then tried to Push my changes and received the following error:

c:\Program Files (x86)\Git\bin\git.exe push --recurse-submodules=check "origin" master:master
remote: error: refusing to update checked out branch: refs/heads/master[K
remote: error: By default, updating the current branch in a non-bare repository[K
remote: error: is denied, because it will make the index and work tree inconsistent[K
remote: error: the work tree to HEAD.[K
remote: error: [K
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to[K
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into[K
remote: error: its current branch; however, this is not recommended unless you[K
remote: error: arranged to update its work tree to match what you pushed in some[K
remote: error: other way.[K
remote: error: [K
remote: error: To squelch this message and still keep the default behaviour, set[K
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.[K
To C:/Development/GIT_Repo/Project
error: failed to push some refs to 'C:/Development/GIT_Repo/Project'

Does anyone know what could be causing this error?


share|improve this question
duplicated: stackoverflow.com/questions/2816369/… –  Cawas Oct 10 '12 at 12:44
add comment

3 Answers

up vote 17 down vote accepted

There are two types of repositories: bare and non-bare

Bare repositories do not have a working copy and you can push to them. Those are the types of repositories you get in Github! If you want to create a bare repository, you can use

git init --bare

So, in short, you can't push to a non-bare repository (Edit: Well, you can't push to the currently checked out branch of a repository. With a bare repository, you can push to any branch since none are checked out. Although possible, pushing to non-bare repositories is not common). What you can do, is to fetch and merge from the other repository. This is how the pull request that you can see in Github works. You ask them to pull from you, and you don't force-push into them.

share|improve this answer
Yes! This is correct thank you! As I have about a million things to do, I accidently cloned the working directory....doh! –  Funky Jun 20 '12 at 11:10
Actually, you can push to a non-bare repository just fine, you just can't push to the one branch that is currently checked out. –  Nowhere man Feb 14 at 15:18
@Nowhereman, that makes sense. But nevertheless, you either have a remote setup just for pushing, which you'd make bare anyway, or it's somebody's working clone, which you don't know which of their branches is checked out, and either way it's not nice to push to someone's working repository (they may be in the middle of something involving that branch). Thanks for the clarification though. –  Shahbaz Feb 14 at 21:01
There are dozens of other scenarios, actually. For example, some of my repositories are just on my workstation and my laptop (not code, but notes I take). On each I have two branches, "workstation" and "laptop". On the workstation, I only check out "workstation", and I only push to the "workstation" branch on the laptop (and vice-versa). –  Nowhere man Feb 15 at 16:50
add comment


You cannot push to the one checked out branch of a repository because it would mess with the user of that repository in a way that will most probably end with loss of data and history. But you can push to any other branch of the same repository.

As bare repositories never have any branch checked out, you can always push to any branch of a bare repository.

Autopsy of the problem

When a branch is checked out, committing will add a new commit with the current branch's head as its parent and move the branch's head to be that new commit.


A ← B


A ← B ← C

But if someone could push to that branch inbetween, the user would get itself in what git calls detached head mode:

A ← B ← X
    ↑   ↑
[HEAD] [branch1]

Now the user is not in branch1 anymore, without having explicitly asked to check out another branch. Worse, the user is now outside any branch, and any new commit will just be dangling:

A ← B ← X

Hypothetically, if at this point, the user checks out another branch, then this dangling commit becomes fair game for Git's garbage collector.

share|improve this answer
I expanded a bit in stackoverflow.com/questions/2816369/… –  Nowhere man Feb 15 at 16:52
add comment

Maybe your remote repo is in the branch which you want to push. You can try to checkout another branch in your remote machine. I did this than these error were disappear, and I pushed success to my remote repo. Notice that I use ssh to connect my own server instead of github.com.

share|improve this answer
add comment

Your Answer


