git push fails: `refusing to update checked out branch: refs/heads/master`

I want to store my local modifications to JBoss config in git. For this, I have set up the following structure:

lrwxrwxrwx  1 jboss jboss        19 Jan 24 11:53 current -> jboss-as-7.1.0.CR1b
drwxr-xr-x 11 jboss jboss      4096 Jan 24 12:13 jboss-as-7.1.0.CR1b
-rw-r--r--  1 jboss jboss 108211143 Jan 23 16:02 jboss-as-7.1.0.CR1b.tar.gz
drwxr-xr-x  6 jboss jboss      4096 Jan 24 11:36 local

local is the git repository which shall be the “origin”. The idea is that I want to be able to easily update my JBoss distribution once an update is available. I want to store all local modifications to the distributed JBoss package in git.

  • git aware but (remote) svn ignore
  • Error after delete permanently a file from my git repository
  • Can I maintain a (non-public) branch of a public github repo in a local TFS server?
  • Maven plugin for versioning and minifying javascript
  • Referring to the same submodule twice
  • When to use “git add .” and when “git add -A”
  • So, currently I do this:

    jboss@tpl0:~/jboss-as-7.1.0.CR1b$ git init
    Initialized empty Git repository in /opt/jboss/jboss-as-7.1.0.CR1b/.git/
    jboss@tpl0:~/jboss-as-7.1.0.CR1b$ git remote add origin ../local/   
    jboss@tpl0:~/jboss-as-7.1.0.CR1b$ git pull origin master 
    From ../local
     * branch            master     -> FETCH_HEAD

    So far so good, all my local modifications are there where I want them.

    However, once I have local modifications and want to bush them back to the local repository, I get an error:

    jboss@tpl0:~/jboss-as-7.1.0.CR1b$ vim standalone/configuration/standalone.xml   
    jboss@tpl0:~/jboss-as-7.1.0.CR1b$ git commit -a -m "renamed database to project2_core,   to distinguish from other projects"
    [master 3e54f34] renamed database to project2_core, to distinguish from other projects
    Committer: jboss <jboss@tpl0.(none)>
     1 files changed, 1 insertions(+), 1 deletions(-)
    jboss@tpl0:~/jboss-as-7.1.0.CR1b$ git push origin master 
    Counting objects: 9, done.
    Compressing objects: 100% (4/4), done.
    Writing objects: 100% (5/5), 447 bytes, done.
    Total 5 (delta 3), reused 0 (delta 0)
    Unpacking objects: 100% (5/5), done.
    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 t
    remote: error: 'ignore' or 'warn' in the remote repository to allow pushing int
    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 som
    remote: error: other way.
    remote: error: 
    remote: error: To squelch this message and still keep the default behaviour, se
    remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
    To ../local/
     ! [remote rejected] master -> master (branch is currently checked out)
    error: failed to push some refs to '../local/'

    What can I do about this? Any help is greatly appreciated!


    Here’s what I did, which solved the problem:

    cd ~/current
    git init
    vim .gitignore                   # set up a basic .gitignore file
    git add .gitignore
    git commit -a -m "initial commit"
    cd ~/local
    git clone ~/current
    git branch -m master current     # rename master branch to 'current'
    git branch repo
    git checkout repo

    Now, the branch current in directory ~/local is always up-to-date, but it’s not cheked out, so that i can push into it.

  • How can I modify the path to git repo in RStudio (.git in higher lever directory than .Rproj)?
  • Why would I want stage before committing in Git?
  • passing ciphers to libcurl through git?
  • How do you ignore whitespace when using git whatchanged -p?
  • What does this sha number in the git path of a gem in a Gemfile mean?
  • With git, how do I remove a local copy of a remote branch? Or at least pull without merging?
  • 6 Solutions collect form web for “git push fails: `refusing to update checked out branch: refs/heads/master`”

    The master branch at remote site is checked out. If you have access to remote repository, checkout any other branch and then push from your repository.

    Pushing is meant for bare repos. For non-bare repos you should pull into them.

    If you want to force this through anyway, you can do as the error message states and set receive.denyCurrentBranch to ignore. SSH to the location of the repo you are pushing to and run:

    git config receive.denyCurrentBranch ignore

    Create the origin (local) repository as a bare repository (ie. git init –bare), or checkout a branch in there which is not master.


    when you initialize your remote project, using

    git init --bare

    I managed to get round this by pulling from ‘local’ in ‘current’ rather than pushing to ‘current’ from ‘local’.

    I know this is quite an old question, but if you go with git init –bare, watch out for ‘GIT_DIR=.’ which will be set for a bare repo hook if using hooks to checkout the repo after pushing. Use ‘export GIT_DIR=.git’ in your hook routine to make it recognise the repo you are pulling into….

    Git Baby is a git and github fan, let's start git clone.