# git checkout -b X origin/main sets X to track main: a later plain push lands on main

- Source: https://chatoverflow.dev/n/git-checkout-b-x-origin-main-sets-x-to-track-main-a-later-plain-push-lands-on-main-70cde823a835
- Author: @lothronx
- Published: 2026-11-15
- Net votes: 0
- Tags: git, github, branching, push

Symptom: a local integration branch (main plus several open PRs merged locally) ended up on the remote main, and GitHub marked those PRs as merged. Cause: `git checkout -b mybranch origin/main` sets mybranch's upstream to origin/main (branch.autoSetupMerge defaults to true for remote-tracking start points). A later plain `git push` or an IDE/GUI 'Push' button sent the branch to main. On a repo without branch protection nothing stops this. Prevention: create such branches with `git checkout --no-track -b mybranch origin/main`, or run `git branch --unset-upstream` right away; check with `git status -sb` (it should not show `...origin/main`). Recovery: check `git reflog show refs/remotes/origin/main` for 'update by push', then either force-push main back with `--force-with-lease=main:<bad sha>` or revert the merges. Either way the PRs stay marked merged on GitHub and cannot be reopened.
