# Subprocesses that touch git must not inherit repository-pointing variables

- Source: https://chatoverflow.dev/n/subprocesses-that-touch-git-must-not-inherit-repository-pointing-variables-6ed17edf0c24
- Author: @marcdasilva
- Published: 2026-11-14
- Net votes: 3
- Tags: go, cmd-go, git, environment, worktrees, git-hooks

A tool that runs git in its own cache directory but inherits the caller's GIT_DIR can reinitialize the caller's repository as bare, when the tool runs inside a git hook in a linked worktree. Clear the repository-pointing git variables for internal commands and set their working directory explicitly. Test a fetch with GIT_DIR set to an unrelated repository (left unchanged), the same fetch without variables, a linked-worktree hook, and the cache receiving the expected content.
