Git and PR Workflow
Produce clean, reviewable history and a clear pull request without corrupting
shared branches or losing work. This workflow is intentionally low-freedom:
history and remote state are hard to recover, so follow the safety rules exactly.
Safety Rules
- Stage explicit paths (
git add path/to/file). Never use git add -A or
git add ., which capture unrelated edits, scratch files, and secrets.
- Never rewrite history that is already published or shared. Rebase, amend, and
squash only commits that live solely on your local branch.
- Never force-push a shared branch. If a rewrite of your own branch is required,
use
git push --force-with-lease, which refuses to overwrite unseen remote work.
- Review the full diff before every commit. Read
git diff --staged in full, not
just the file list.
- Keep one logical change per commit. Unrelated changes belong in separate commits.
- Write commit subjects in the imperative mood: "Add", "Fix", "Rename".
Start Work
- Confirm a clean starting point with
git status. Stash or commit unrelated
local changes before branching.
- Update the base branch:
git switch main then git pull --ff-only.
- Create a topic branch:
git switch -c <type>/<short-description>. Use a
descriptive slug such as fix/login-null-check.
- Confirm the new branch and base with
git status before editing.
Commit Changes
- Review every change with
git status and git diff.
- Group related edits. Stage each group by explicit path.
- Re-read the staged diff with
git diff --staged. Unstage anything unrelated.
- Scan the staged diff for secrets, credentials, tokens, and debug output before
committing.
- Commit with a clear subject and, when the change needs justification, a body.
See commit message rules.
- Split accidental mixed changes: unstage, then re-stage one logical group at a
time so each commit stands alone.
Keep History Current
- Prefer rebase over merge to integrate the latest base into an in-progress,
unshared branch:
git fetch then git rebase origin/main.
- If the branch is already shared and others may have based work on it, merge the
base in instead of rebasing, to avoid rewriting shared commits.
- To tidy local-only commits before review, use
git rebase -i to reorder,
squash, or reword. Never do this to commits others already pulled.
- Resolve any conflicts that arise, then continue. See
worktrees and conflicts.
- After a rebase, push your own branch with
git push --force-with-lease, never
plain --force.
Resolve Conflicts
- Read
git status to list conflicted files.
- Open each file and reconcile the intent of both sides. Do not blindly keep one
side or delete the markers without understanding the change.
- Remove all conflict markers, then stage the resolved file by explicit path.
- Run the repository's test command to confirm the resolution is correct.
- Continue the operation with
git rebase --continue or git merge --continue.
Abort with --abort if the resolution is unclear and a fresh attempt is safer.
See worktrees and conflicts for
worktree-based isolation.
Open a Pull Request
- Push the branch:
git push -u origin <branch>.
- Confirm the diff against the base is exactly the intended change; remove stray
commits first.
- Write the description so a reviewer needs no other context:
- What changed and why, in the first sentences.
- The problem or issue it addresses, with a link when one exists.
- How it was verified, naming the commands run.
- Risks, follow-ups, and anything intentionally out of scope.
- Keep the pull request focused on one logical change. Split unrelated work into
separate pull requests.
Finish a Branch
- Confirm the change is merged into the base and the base is updated locally.
- Verify no unpushed commits remain:
git log origin/<branch>..HEAD returns nothing.
- Delete the local branch (
git branch -d, which refuses unmerged work) and the
remote branch when the platform did not remove it.
- Remove any worktree created for the branch:
git worktree remove <path>.
- Return to an updated base branch and confirm a clean
git status.
Report
State the branch, the commits made, verification commands run and their result,
the pull request opened or updated, and any cleanup still pending.
1---2name: git-and-pr-workflow3description: Guides Git branching, atomic commits, rebasing, resolving merge conflicts, worktrees, pull request descriptions, and safely finishing a branch. Use when creating branches, staging and committing changes, rebasing or squashing, resolving conflicts, opening or updating a pull request, or cleaning up after merge.4license: MIT5---67# Git and PR Workflow89Produce clean, reviewable history and a clear pull request without corrupting10shared branches or losing work. This workflow is intentionally low-freedom:11history and remote state are hard to recover, so follow the safety rules exactly.1213## Safety Rules1415* Stage explicit paths (`git add path/to/file`). Never use `git add -A` or16 `git add .`, which capture unrelated edits, scratch files, and secrets.17* Never rewrite history that is already published or shared. Rebase, amend, and18 squash only commits that live solely on your local branch.19* Never force-push a shared branch. If a rewrite of your own branch is required,20 use `git push --force-with-lease`, which refuses to overwrite unseen remote work.21* Review the full diff before every commit. Read `git diff --staged` in full, not22 just the file list.23* Keep one logical change per commit. Unrelated changes belong in separate commits.24* Write commit subjects in the imperative mood: "Add", "Fix", "Rename".2526## Start Work27281. Confirm a clean starting point with `git status`. Stash or commit unrelated29 local changes before branching.302. Update the base branch: `git switch main` then `git pull --ff-only`.313. Create a topic branch: `git switch -c <type>/<short-description>`. Use a32 descriptive slug such as `fix/login-null-check`.334. Confirm the new branch and base with `git status` before editing.3435## Commit Changes36371. Review every change with `git status` and `git diff`.382. Group related edits. Stage each group by explicit path.393. Re-read the staged diff with `git diff --staged`. Unstage anything unrelated.404. Scan the staged diff for secrets, credentials, tokens, and debug output before41 committing.425. Commit with a clear subject and, when the change needs justification, a body.43 See [commit message rules](references/commit-messages.md).446. Split accidental mixed changes: unstage, then re-stage one logical group at a45 time so each commit stands alone.4647## Keep History Current48491. Prefer rebase over merge to integrate the latest base into an in-progress,50 unshared branch: `git fetch` then `git rebase origin/main`.512. If the branch is already shared and others may have based work on it, merge the52 base in instead of rebasing, to avoid rewriting shared commits.533. To tidy local-only commits before review, use `git rebase -i` to reorder,54 squash, or reword. Never do this to commits others already pulled.554. Resolve any conflicts that arise, then continue. See56 [worktrees and conflicts](references/worktrees-and-conflicts.md).575. After a rebase, push your own branch with `git push --force-with-lease`, never58 plain `--force`.5960## Resolve Conflicts61621. Read `git status` to list conflicted files.632. Open each file and reconcile the intent of both sides. Do not blindly keep one64 side or delete the markers without understanding the change.653. Remove all conflict markers, then stage the resolved file by explicit path.664. Run the repository's test command to confirm the resolution is correct.675. Continue the operation with `git rebase --continue` or `git merge --continue`.68 Abort with `--abort` if the resolution is unclear and a fresh attempt is safer.69 See [worktrees and conflicts](references/worktrees-and-conflicts.md) for70 worktree-based isolation.7172## Open a Pull Request73741. Push the branch: `git push -u origin <branch>`.752. Confirm the diff against the base is exactly the intended change; remove stray76 commits first.773. Write the description so a reviewer needs no other context:78 - What changed and why, in the first sentences.79 - The problem or issue it addresses, with a link when one exists.80 - How it was verified, naming the commands run.81 - Risks, follow-ups, and anything intentionally out of scope.824. Keep the pull request focused on one logical change. Split unrelated work into83 separate pull requests.8485## Finish a Branch86871. Confirm the change is merged into the base and the base is updated locally.882. Verify no unpushed commits remain: `git log origin/<branch>..HEAD` returns nothing.893. Delete the local branch (`git branch -d`, which refuses unmerged work) and the90 remote branch when the platform did not remove it.914. Remove any worktree created for the branch: `git worktree remove <path>`.925. Return to an updated base branch and confirm a clean `git status`.9394## Report9596State the branch, the commits made, verification commands run and their result,97the pull request opened or updated, and any cleanup still pending.