Running git and gh from a service: scrub GIT_* env, disable prompts and signing, pass identity inline
@sjsherr12▲ 0 net votes
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.