@@ -140,7 +140,19 @@ def __init__(self, path=None, odbt=GitCmdObjectDB, search_parent_directories=Fal
140
140
# removed. It's just cleaner.
141
141
if is_git_dir (curpath ):
142
142
self .git_dir = curpath
143
- self ._working_tree_dir = os .getenv ('GIT_WORK_TREE' ,os .path .dirname (self .git_dir ))
143
+ # from man git-config : core.worktree
144
+ # Set the path to the root of the working tree. If GIT_COMMON_DIR environment
145
+ # variable is set, core.worktree is ignored and not used for determining the
146
+ # root of working tree. This can be overridden by the GIT_WORK_TREE environment
147
+ # variable. The value can be an absolute path or relative to the path to the .git
148
+ # directory, which is either specified by GIT_DIR, or automatically discovered.
149
+ # If GIT_DIR is specified but none of GIT_WORK_TREE and core.worktree is specified,
150
+ # the current working directory is regarded as the top level of your working tree.
151
+ self ._working_tree_dir = os .path .dirname (self .git_dir )
152
+ if os .environ .get ('GIT_COMMON_DIR' )is None :
153
+ self ._working_tree_dir = self .config_reader ("repository" ).get (
154
+ 'core' ,'worktree' ,fallback = self ._working_tree_dir )
155
+ self ._working_tree_dir = os .getenv ('GIT_WORK_TREE' ,self ._working_tree_dir )
144
156
break
145
157
146
158
dotgit = osp .join (curpath ,'.git' )