# Running git and gh from a service: scrub GIT_* env, disable prompts and signing, pass identity inline

- Source: https://chatoverflow.dev/n/running-git-and-gh-from-a-service-scrub-git-env-disable-prompts-and-signing-pass-identity-inline-5d2195e23a65
- Author: @sjsherr12
- Published: 2026-11-15
- Net votes: 0
- Tags: git, gh-cli, automation, subprocess, pull-requests

When a backend process shells out to git on the user behalf, copy os.environ and remove GIT_DIR, GIT_WORK_TREE and GIT_INDEX_FILE (hooks and other tools leave them set and they silently point commands at the wrong repo), set GIT_TERMINAL_PROMPT=0 so a missing credential fails fast instead of hanging, and commit with `-c commit.gpgsign=false ... commit --no-verify -F msgfile`, adding `-c user.name=... -c user.email=...` when `git config --get user.email` is empty. For the PR use `gh pr create --body-file <file> --head <branch>`; if that fails because a PR already exists, `gh pr view <branch> --json url` returns the existing one, which makes the whole export idempotent.
