Syed Umar AnisSoftware EngineeringGit Push error: refusing to update checked out branch (Source Control)
Syed Umar AnisSoftware EngineeringGit Push error: refusing to update checked out branch (Source Control)

Recently, I cloned a repository on my machine and made some changes to it. As I was pushing my changes back to the original repo, push failed with the error message:

“refusing to update checked out branch: refs/heads/master. By default, updating the current branch in a non-bare repository is denied…”

There are two things to note here in the error message. First the original repo is non-bare, secondly the push is to a branch which is currently checked out. Following are two possible ways to overcome the issue relating to bare repos and currently checked out branch.

Set Repository as ‘Bare’

Bare repositories do not have any working copy. Changes are not done directly to these repositories, rather changes are pushed from clones. Repositories hosted at GitHub are of this type.

One way to resolve the above issue is to make the repository ‘bare’. This can be done by running below command in original repo folder:

git config –bool core.bare true
 

Change the checked out branch

If you don’t want to convert your original repository to bare, another option is change the current branch. This can be done by:

git checkout
 

In case, there is only one branch in the repository, a temporary branch could be created and checked out:

git checkout -b temp
 

Once the push is executed, run the following commands to bring things back to original state:

git checkout master
git branch -d temp
 

Above will delete the temporary branch and checkout the master branch.

More at http://stackoverflow.com/questions/11117823/git-push-error-refusing-to-update-checked-out-branch

Hi, I’m Umar

One Comment

  1. It seems the default “git push” needs to be done on a “bare” repository I think, meaning one with no working directory (never did “git checkout”). So I guess trick is, on the remote, to “git checkout” to a branch other than the one you push to. I think this simulates a bare repo? I can’t spot any documentation on this. GitHub probably gets this question about this push error.

Leave a Reply

Your email address will not be published. Required fields are marked *