diff --git a/share/Makefile.headers b/share/Makefile.headers
index 8b243dae3572ba7dee6db4460a360ca5783018bc..7a0c6af0ae26e11fd953223c9dc08a5beed7d3e1 100644
--- a/share/Makefile.headers
+++ b/share/Makefile.headers
@@ -106,8 +106,8 @@ HDRCK.FILE_ATTR=$(GIT) check-attr --stdin -z header_spec
 
 ifeq ($(HEADER_SPEC),)
 
-HDRCK.HAS_GIT:=$(wildcard .git)
-ifneq ($(HDRCK.HAS_GIT),)
+HDRCK.HAS_GIT:=$(shell git rev-parse --is-inside-work-tree 2> /dev/null)
+ifeq ($(HDRCK.HAS_GIT),true)
 
 # From git (including git work-trees)
 HDRCK.SPEC:=$(HDRCK.FILE_LIST) | $(HDRCK.FILE_ATTR)
@@ -124,8 +124,8 @@ else # HEADER_SPEC
 
 ifeq ($(HEADER_SAVE_SPEC),yes)
 
-HDRCK.HAS_GIT:=$(wildcard .git)
-ifneq ($(HDRCK.HAS_GIT),)
+HDRCK.HAS_GIT:=$(shell git rev-parse --is-inside-work-tree 2> /dev/null)
+ifeq ($(HDRCK.HAS_GIT),true)
 
 # From git (including git work-trees)
 HDRCK.SPEC:= $(HDRCK.FILE_LIST) | $(HDRCK.FILE_ATTR) | $(TEE) $(HEADER_SPEC)
diff --git a/share/Makefile.linting b/share/Makefile.linting
index afaf8e870e5e65b0d3f9494bcaa5e3b7d153d452..700afae655885924d84ba20208a9b2aa3b70e1b9 100644
--- a/share/Makefile.linting
+++ b/share/Makefile.linting
@@ -161,8 +161,8 @@ LINT.check-targets= \
 LINT.fix-targets=$(subst check-,fix-,$(LINT.check-targets))
 LINT.main-targets=lint $(LINT.check-targets) $(LINT.fix-targets)
 
-LINT.HAS_GIT:=$(wildcard .git)
-ifeq ($(LINT.HAS_GIT),)
+LINT.HAS_GIT:=$(shell git rev-parse --is-inside-work-tree 2> /dev/null)
+ifneq ($(LINT.HAS_GIT),true)
 
 .PHONY: lint
 lint: