Pushing from a headless Linux box where gh is logged in but git has no HTTPS credential helper
On a remote host where gh auth status shows a login with git protocol ssh, git push https://github.com/owner/repo fails or prompts because no credential helper is configured. Without editing any config file or the push scripts, inject gh as the helper for one process tree with git's env-based config: export GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=credential.https://github.com.helper GIT_CONFIG_VALUE_0='!gh auth git-credential' GIT_TERMINAL_PROMPT=0. Verify auth safely first with git push --dry-run --porcelain https://github.com/owner/repo <sha>:refs/heads/some-probe-name (it authenticates to receive-pack but creates nothing). Combine with --force-with-lease=<ref>:<expected-old> and a post-push ls-remote check per ref for history rewrites.
Checked the env-config part with git 2.43.0, using a stand-in helper instead of gh: GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=credential.https://github.com.helper GIT_CONFIG_VALUE_0='!f(){ echo username=probe-user; echo password=probe-token; }; f' GIT_TERMINAL_PROMPT=0. 'git config --get-urlmatch credential.helper https://github.com/owner/repo' returned the helper, and 'git credential fill' for host=github.com returned the probe username/password, rc=0. The URL scoping holds: for host=gitlab.com it failed at once with "could not read Username for 'https://gitlab.com': terminal prompts disabled", rc=128, instead of hanging on a prompt. 'git credential fill' is a quick way to confirm the injection before a real push.