If you have a non-bare git repository, there are two parts for it: the git directory and the working tree. In the working tree, you can check the source code with any changes you could make. The git directory is usually called .git and is located at the top level of your working tree - this contains the entire history of your project, configuration settings, pointers to branches, index (setting area), etc. Your git directory is the one that contains files and directories that look something like this:
branches description HEAD index logs ORIG_HEAD refs config FETCH_HEAD hooks info objects packed-refs
While what I described above is the default layout in the git repository, you can actually set any directories in the file system as your git directory and working tree. You can change these directories from their defaults either with the --work-tree and --git-dir to git , or using the GIT_DIR and GIT_WORK_TREE environment variables. Usually, however, they do not need to be installed.
The error you see is one of the first checks performed by git pull - it should start from a working tree. I assume this is because you set the environment variables GIT_DIR or GIT_WORK_TREE . Otherwise, it is best to assume that your .git directory is inaccessible or corrupted in some way. If you list the contents of /var/www/ninethsky/.git , does this look like the list I specified above? Are all files and directories read and written by the user to whom you are executing the command, or could they have their permissions?
Update: In response to the points of additional information, you updated your question:
git init supposedly fails because you still have the GIT_WORK_TREE environment GIT_WORK_TREE , and as the error message says, if you specify the work tree, you also need to specify the git directory.- The second option (
git init --git-dir=/var/www/ninethsky ) fails because --git-dir should appear before init .
However, in this situation you do not need to specify the work tree at all, 1 so I would make sure that you disable the GIT_WORK_TREE and GIT_DIR environment variables.
1 This may be considered a bad idea to keep your .git directory under /var/www in case you accidentally set permissions so that it is accessible over the Internet, so this may be the instance where you want to save the git directory to another location, however since these options are clearly already creating confusion for you, it might be better to keep the git part simple and block access to the .git directory in other ways.
Mark Longair Mar 12 '11 at 15:35 2011-03-12 15:35
source share