I try to keep a Git change small enough to explain in one sentence. This is the sequence I use to check the branch, review what I changed, and share it for review.
You will need Git, a cloned repository with an origin remote and a main branch. Replace the example names with your own, and check each result before moving on.
1. Check where you are
Start with the current branch and working tree. git diff shows tracked edits that are not staged; untracked files appear in git status. Commit or deliberately stash existing work before switching branches if it belongs to another task.
A clean working tree makes the following steps easier to reason about. These commands inspect the repository without changing its files.
git status --short --branch
git diff
git log -5 --oneline2. Start from the current main branch
Switch to main, bring it forward, then create a branch for one task. --ff-only stops if your local main has diverged, giving you a chance to inspect the history before choosing how to reconcile it.
After the final command, git status should show feat/contact-form as the current branch. Make the intended edit in your editor before continuing.
git switch main
git pull --ff-only origin main
git switch -c feat/contact-form3. Stage the change you intend to commit
Replace src/contact.ts with a file you actually changed. Staging a named file makes the scope explicit. For a file containing several unrelated edits, git add -p lets you review and stage individual hunks.
Read the staged diff. It is the content of the next commit, which may differ from the current working copy if you edited the file again after staging.
git diff
git add src/contact.ts
git diff --staged
git status --short4. Unstage a file when the scope is wrong
If the file does not belong in this commit, remove it from the staging area. --staged leaves its working-tree edits in place. Check git diff to confirm your edits are still there, then stage the intended files again.
git restore --staged src/contact.ts
git diff5. Check, commit, and share
Run the build or checks appropriate to your project before committing. The message should describe the change clearly enough to distinguish it from the next commit.
Push the feature branch, then open a pull request in your hosting service. -u sets its upstream so future pushes from this branch can use git push. Finally, git status should show any remaining local changes rather than silently hiding them.
git commit -m "Add contact form validation"
git push -u origin feat/contact-form
git status