1

i am new to git. in the foreseeable future i will be the only developer for the project in question so i am not worried about becoming a git expert at this point. i just want to push my changes to the production server.

development machine has snow leopard os. i installed git. used git init, add and commit.

remote production server has ubuntu 10. i installed git and used git init.

then "ssh://me@domain.com:00000/path_to_project_root/.git master:master"

getting the following error:

"refusing to update checked out branch: refs/heads/master. By default, updating the current branch in a non-bare repository is denied, because it will make the index and work tree inconsistent with what you pushed, and will require 'git reset --hard' to match the work tree to HEAD. You can set 'receive.denyCurrentBranch' configuration variable t 'ignore' or 'warn' in the remote repository to allow pushing int its current branch; however, this is not recommended unless you arranged to update its work tree to match what you pushed in som other way. To squelch this message and still keep the default behaviour, set 'receive.denyCurrentBranch' configuration variable to 'refuse'... [remote rejected] master -> master (branch is currently checked out)"

any help is appreciated.

Jay
  • 6,206
  • 11
  • 48
  • 82
  • i found GitCasts and expect that to help with basic knowledge. currently reading a substantial volume on rails but will add Pro Git to my reading list. – Jay May 22 '11 at 16:59
  • Possible duplicate of http://stackoverflow.com/questions/3191400/pushing-to-a-git-repository-does-not-work and http://stackoverflow.com/questions/2816369/git-push-error-remote-rejected-master-master-branch-is-currently-checked-ou and many others – Mark Longair May 22 '11 at 17:18

1 Answers1

2

This error is asked about very frequently on Stack Overflow, and everything you need to know is described in the error message if you understand the terms used. In the comments on your question I've linked to a couple of other questions that deal with the same error, but I'll add a quick summary here anyway.

Essentially there are two types of repository in git - bare repositories and non-bare. When you need to work on code, you're almost always using a non-bare repository, which at the top level has:

  • a .git directory (containing all the history of your project)
  • everything else in that top level directory, typically all the source code you're working on

The latter is the "working tree".

A bare repository is like just the .git directory on its own. That means, for example, that a bare repository can never have local changes and you can't do any merge in one that might create conflicts.

If you try to push to the branch which is currently checked out in a non-bare repository, git has a problem. If it doesn't touch the working tree, but updates the branch, the results from git status will suddenly look very confusing - any files that were added in the new commits from the branch will appear as deleted in git status and your local changes and those introduced by the new commits will be all mixed up. If git just updates your working tree, it might overwrite local changes you had there.

Normally the recommendation is that you only push to bare repositories. However, there are various ways around that - for example, the following answer in the git FAQ suggests a couple:

In this case, since you want the push to this repository to deploy your code, you could try the hook linked to there, which makes pushing into a non-bare repository safer than just a hook that throws away the local changes with git reset --hard or similar.

Mark Longair
  • 446,582
  • 72
  • 411
  • 327
  • thanks. i get it. good explanation. i never do make any changes on the remote server. perhaps i should not have run 'git init' on the remote directory? so now i need to figure out how to make the repository on the remote server a bare repository. – Jay May 22 '11 at 17:56
  • 2
    @Jay: When you're logged in to the remote repository, you can clone it with `git clone --bare [path-to-non-bare-repository]` and then locally update the URL that origin points to so that it refers to the bare version instead. – Mark Longair May 22 '11 at 18:03
  • all your help items are worth points :=]. OK... tried that and the error i got was "git clone --bare ~/public_html/domain_bare Initialized empty Git repository in /home/jay/public_html/domain/domain_bare.git/ fatal: failed to open '/home/jay/public_html/domain_bare/objects': No such file or directory" On the remote domain directory i did a 'git init'. I suppose there was something else i was supposed to do? – Jay May 22 '11 at 18:21
  • tried to do git init --bare on the remote server and got 'fatal: Out of memory? mmap failed: No such device' ... ugh. – Jay May 22 '11 at 18:36
  • 2
    In `git clone --bare ` the path should be the existing non-bare repository. If you want to create a completely fresh bare repository you can just do: `mkdir whatever.git` then `cd whatever.git` and finally `git init --bare` Incidentally, it's awkward to answer further questions properly in comments - it's probably best to post a new question if you have futher issues. – Mark Longair May 22 '11 at 18:37