Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git error "fatal: GIT_WORK_TREE (or --work-tree=<directory>) not allowed without specifying GIT_DIR (or --git-dir=<directory>)"

I have GIT_WORK_TREE set to . and GIT_DIR set to .git. When I run git init --bare, I get the following error:

fatal: GIT_WORK_TREE (or --work-tree=<directory>) not allowed without specifying GIT_DIR (or --git-dir=<directory>)

What's up with that? I suspect that it might have something to do with GIT_DIR being set to . (maybe it considers GIT_DIR unset if it points to the current working directory?). Regardless, it would be great to have this behave properly so I don't have to unset GIT_WORK_TREE every time I want to initialize a Git repo.

like image 471
joshlf Avatar asked Aug 07 '14 00:08

joshlf


1 Answers

This error message comes from builtin/init-db.c

    /*
     * GIT_WORK_TREE makes sense only in conjunction with GIT_DIR
     * without --bare.  Catch the error early.
     */
    git_dir = getenv(GIT_DIR_ENVIRONMENT);
    work_tree = getenv(GIT_WORK_TREE_ENVIRONMENT);
    if ((!git_dir || is_bare_repository_cfg == 1) && work_tree)
        die(_("%s (or --work-tree=<directory>) not allowed without "
              "specifying %s (or --git-dir=<directory>)"),

So on Unbuntu, unset GIT_WORK_TREE just before doing a git init --bare.
See "Unset an environmental variable for a single command":

env -u GIT_WORK_TREE git init --bare
# or
GIT_WORK_TREE=  git init --bare

I'm adding remote on windows perfectly

git init --bare is not "adding remote", so you need to check what command triggers that error message.


On Windows, use cmd /V/ /C as explained here:

cmd /V /C "set "GIT_WORK_TREE=" && git init --bare"
like image 74
VonC Avatar answered Nov 10 '22 21:11

VonC