Git + PR Flow Cheat Sheet
Daily pre-flight
Always start from staging and sync with remote:
git checkout staging
git pull --rebase origin staging
-
Makes sure local
stagingincludes:- All merged PRs from GitHub
- My work, rebased on top
-
If there are conflicts, fix,
git add, then:
git rebase --continue
My normal work on staging
git checkout staging # if not already
# edit in VS Code
git status # see changes
git add . # or specific files
git aic # my epic ai-commits cli-app (@taksumaq/aicommits)
git push origin staging
This keeps origin/staging as the source of truth for staging + deploys.
When a collaborator opens a PR
Decide merge vs close
This is the real decision point. Once merged,
origin/stagingnow “wants” those changes.
Sync that decision locally
After merging/closing the PR:
git checkout staging
git pull --rebase origin staging
-
If merged:
- Pull brings in the merged commits.
- My local work is rebased on top.
-
If closed:
- Pull is usually a no-op (already up to date).
Then I keep working as usual (commit + push).
Testing a PR locally
Example PR branch collab-feature-x → staging.
Getting the PR branch locally
git fetch origin
git checkout -b collab-feature-x origin/collab-feature-x
- Now I’m on a local copy of the PR branch.
- I can run dev server, test, read copy, etc.
If I’m good with it → merge into staging
git checkout staging
git pull --rebase origin staging # make sure staging is current
git merge --no-ff collab-feature-x # merge PR branch into staging
git push origin staging # update GitHub
GitHub will auto-detect that the PR’s commits are now in staging and mark the PR as merged.
Otherwise → don’t merge
- Locally, I can drop the branch:
git branch -d collab-feature-x
Using GitHub CLI (gh) for PRs (optional, terminal-native)
From inside the repo:
List PRs
gh pr list
View a PR
gh pr view 12 # PR #12
Checkout a PR branch locally
gh pr checkout 12
(This is equivalent to git fetch + git checkout -b ... origin/....)
Merge a PR from terminal
gh pr merge 12 --merge
--merge→ normal merge commit- After this, sync locally:
git checkout staging
git pull --rebase origin staging
Close (reject) a PR from terminal
gh pr close 12
Cleaning up branches
After a PR is merged / closed
Delete remote branch:
git push origin --delete collab-feature-x
(or use the “Delete branch” button on GitHub after merge).
Prune remote-tracking refs locally:
git fetch --prune origin
Delete local branch:
git branch -d collab-feature-x
Quick “safe sync” patterns
Before starting any work
git checkout staging
git pull --rebase origin staging
After merging PRs on GitHub
git checkout staging
git pull --rebase origin staging
When things feel off
- Make backup branch:
git branch backup/local-snapshot-YYYYMMDD
-
Then
pull --rebase, conflict fixes, etc. -
Delete backup later if happy:
git branch -d backup/local-snapshot-YYYYMMDD