git sync when starting/resuming work and after PR mergesmain via PR + squash merge using gh (CLI)main clean.main stays simple and “green”.Install git & GitHub CLI and authenticate
winget install --id Git.Git -e --source winget
winget install --id GitHub.cli -e
gh auth login
git config --global alias.sync "fetch --prune"
git config --global fetch.prune true
git config --global pull.ff only
git config --global alias.lg "log --oneline --decorate --graph -20"
git config --global alias.br "branch --show-current"
git switch main
git sync
git merge --ff-only origin/main
If the last line fails, stop and inspect:
git status
git lg
(You should not “force it”. Decide intentionally.)
$branch="fix/readme-typos"
git status
git switch -c $branch
If the branch already exists:
git switch $branch
git status
git add -A
git commit
git push -u origin $branch
git add -A
git commit
git push
git push is rejected (rare for you)This means “remote has commits you don’t have”.
Beginner-safe fix (no rebase):
git fetch --prune
git merge --no-edit '@{u}'
git push
If the merge conflicts: resolve, commit, push.
From your feature branch:
gh pr create --base main --fill
--base main targets main--fill uses commit(s) to populate title/body (GitHub CLI)When you don’t use auto-merge / checks:
gh pr merge --squash --delete-branch
If your repo requires checks and you want it to merge when ready:
```powershell
gh pr merge --auto --squash --delete-branch
```
Flags are official: --squash, --delete-branch, --auto. (GitHub CLI)
main after merge (NOT always needed)git switch main
git sync
git merge --ff-only origin/main
If gh pr merge --delete-branch didn’t remove your local branch (it can vary by setup), delete it explicitly:
git branch -d $branch
main advanced (Codex PR merged)”Update your branch explicitly (no rebase):
git switch $branch
git sync
git merge origin/main
Then continue work, test, push, and (later) PR + squash merge again.
temporarily relax “PR always” for tiny fixes.
git switch main; git sync; git merge --ff-only origin/main
# edit typo
git add -A; git commit; git push
Two common cases.
$repo="my-new-project"
gh repo create $repo --private --clone
cd $repo
gh repo create supports --private/--public and --clone. (GitHub CLI)
Then add your initial files:
ni README.md
git add -A
git commit -m "Initial commit"
git push -u origin main
From inside your project directory:
git init
git add -A
git commit -m "Initial commit"
gh repo create --source=. --private --push
--source=. creates the GitHub repo from the current directory--push pushes your initial commit(s) (GitHub CLI)