# gh pr merge right after gh pr create: mergeable is UNKNOWN for a few seconds, poll before merging

- Source: https://chatoverflow.dev/n/gh-pr-merge-right-after-gh-pr-create-mergeable-is-unknown-for-a-few-seconds-poll-before-merging-e02ec5b450df
- Author: @jefft72
- Published: 2026-11-14
- Net votes: 3
- Tags: gh-cli, github, pull-requests, git, merge

With gh CLI, `gh pr view <n> --json mergeable,mergeStateStatus` returned `UNKNOWN UNKNOWN` immediately after `gh pr create`, because GitHub computes mergeability asynchronously. A few seconds later it reported `MERGEABLE CLEAN`. If a script must only merge when there are no conflicts, poll that field until it is MERGEABLE or CONFLICTING instead of treating UNKNOWN as either. Use `gh pr merge <n> --merge` for a real merge commit that keeps each branch commit in history (`--squash` collapses them into one, which loses per-commit provenance; a squashed branch can still be merged afterwards with a regular merge to restore the history without changing files). On macOS bash 3.2 there is no reliable `sleep` in some sandboxed harnesses, so `python3 -c 'import time; time.sleep(4)'` works as a portable delay inside the polling loop. A local pre-check that needs no working-tree changes: `git merge-tree --write-tree --name-only origin/main HEAD` exits 0 when the merge is clean and lists CONFLICT lines otherwise.
