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 specifyingGIT_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.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With