0

I read several SO posts on that issue but I can't figure out what I am doing wrong. I try to push my commit to a remote branch but I get error: failed to push some refs to 'k:/home/projects/tmp/rest-backend'

Working directory

I have one WD called rest-backend and one called rest-backend-branch. The second one was created using the git clone rest-backend rest-backend-branch.

k:\home\projects\tmp\rest-backend-branch>git remote -v
origin  k:/home/projects/tmp/rest-backend (fetch)
origin  k:/home/projects/tmp/rest-backend (push)

Repository Logs

k:\home\projects\tmp\rest-backend>git log --pretty=oneline --abbrev-commit -4
8526101 Fix sort order
57bbc5b Add favicon
f7a2a24 New client
4f01419 Handle deep link

k:\home\projects\tmp\rest-backend-branch>git log --pretty=oneline --abbrev-commit -4
5294da8 New client
8526101 Fix sort order
57bbc5b Add favicon
f7a2a24 New client

The rest-backend-branch is 1 commit ahead of origin/master as displayed by git status.

k:\home\projects\tmp\rest-backend-branch>git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working directory clean

Push my commit to remote

If I try to push my commit to origin/master, I get that error.

k:\home\projects\tmp\rest-backend-branch>git push origin master
Counting objects: 29, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (11/11), done.
Writing objects: 100% (11/11), 101.71 KiB | 0 bytes/s, done.
Total 11 (delta 3), 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 k:/home/projects/tmp/rest-backend
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'k:/home/projects/tmp/rest-backend'

How do I fix this?

Sydney
  • 11,964
  • 19
  • 90
  • 142

1 Answers1

1

To fix it, you can just follow the instructions in the error message. Set receive.denyCurrentBranch to whatever value suits you - ignore or warn

But we aware of the results.

What you have done here is that you cloned non-bare repository, i.e. this repository has a working directory.

If this working directory is now set to master branch, and you push changes to this branch - your working directory becomes detached from the branch and you have to run there git reset --hard

Some other solutions for you would be:

  • Clone only bare repositories. (Or at least, don't push to non bare repositories)
  • Change the working directory on the remote repository to be on another branch.
Igal S.
  • 13,146
  • 5
  • 30
  • 48
  • I fixed it by creating a bare repository. Thanks for pointing out that I should not clone not bare repository. – Sydney Nov 22 '15 at 14:56