SOLVED [git] refusing to update checked out branch: refs/heads/master


On the “upstream” git.server.local
  1. cd /vault/projects
  2. git init project.git
  3. touch project/.git/git-daemon-export-ok
On the “downstream” workstation.local
  1. cd /views/projects
  2. git clone ssh://git.server.local/vault/projects/project.git
  3. … edit stuff …
  4. git add -u
  5. git commit --message "fixed many bugs"
  6. git push
    This will fail as described below


$ git push
Counting objects: 13, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (10/10), done.
Writing objects: 100% (10/10), 3.08 KiB | 0 bytes/s, done.
Total 10 (delta 4), 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.        
remote: error:         
remote: error: To squelch this message and still keep the default behaviour, set        
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.        
To ssh://git.server.local/vault/projects/project.git
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'ssh://git.server.local/vault/projects/project.git'


On the first push upstream:

git push origin +refs/heads/master

Subsequent pushes upstream do not require an explicit indicator of what to push

All the advice below here is misdirective (true but unhelpful in this context).

On the “upstream” git.server.local
  1. cd /vault/projects/project
  2. git branch undefined
    (create a branch with any other name but master)
  3. git checkout undefined
    Switch the checked-out view branch undefined which you never intend to use
  4. git branch
    * undefined
On the “downstream” workstation.local
  1. git push
    … now succeeds
  2. rinse & repeat.


This is a super-confusing condition and is the default condition. It’s not what you’re used to experiencing with Subversion or with Github in the upstream/downstream mode.

Git refers to its “checkout” state as being “logged in” to a view. You can’t push changes from a branch in one repository over to a branch in another repository which is in the “checked out” or “logged in” state. When a repository is created, the master branch is in the “logged in state” by virtue of being checked out.