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 wha开发者_JS百科t 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.
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:
- Why won't I see changes in the remote repo after "git push"?
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.
精彩评论