The feature-branch & pull-request workflow
How most teams actually ship changes, step by step.
1 Learn the idea
Almost every team uses the same loop: nobody commits directly to main. Each change lives on its own feature branch, gets pushed, reviewed in a pull request (PR, called merge request on GitLab), and is merged into main on the server.
The loop
git switch mainandgit pull: start from the latest version.git switch -c my-feature: a fresh branch for this one change.- Commit as often as you like.
git push -u origin my-feature, then open a PR on GitHub.- After review, the PR gets merged on origin (the GitHub button).
- Back home:
git switch main,git pull,git branch -d my-feature.
2 Watch it happen
Press Play or use → to step through. Watch the graph as each command runs.
Read this demo as text
$ git switch -c dark-mode
Start a feature branch from an up-to-date
main. It is just a new label on the same commit.$ edit theme.css "body { background: #111 }" $ git add theme.css $ git commit -m "Add dark theme"Work and commit on the branch.
maindoes not move.$ edit toggle.js "toggleTheme()" $ git add toggle.js $ git commit -m "Add theme toggle"
Another commit. Small, focused commits make reviewing easy.
$ git push -u origin dark-mode
Publish the branch. A new
dark-modeappears on origin and your branch now tracksorigin/dark-mode. On GitHub you would click "Compare & pull request" now.$ teammate merge dark-mode
Sam reviews the PR and clicks Merge. The merge commit is created on origin — look at the top panel. Your laptop does not know yet.
$ git switch main
Back to
main. Locally it still points to the old commit.$ git pull
Pull brings the merge commit down. Your
mainfast-forwards to match origin: the feature is officially in.$ git branch -d dark-mode
-ddeletes the local branch label. It is safe: git only allows it because the commits are already part ofmain.$ git push origin --delete dark-mode
Tidy up the remote branch too (GitHub has a button for this). The commits stay in history; only the label is gone.
git branch -drefuses to delete unmerged work.-Dforces it, so use it only when you really mean "throw this away".- Name branches after the change:
fix-login-timeout,add-dark-mode. - Never commit directly to
mainon a team repo, even for tiny fixes.
git switch -c <feature>Start a feature branchgit push -u origin <feature>Publish it and open a PRgit pull origin mainBring new main commits into your branchgit branch -d <feature>Delete a merged branch locally3 Check your understanding
Where does the merge of a pull request usually happen?
Your PR has been merged. What is the usual clean-up?
Look at the graph. Can git branch -d feature succeed right now while on main?
While your PR is open, main gets 5 new commits. Which is a reasonable way to update your feature branch?
4 Practice for real
Ship a fix through a PR
Fix the README through the full workflow: create branch fix-typo, commit a change, publish it, get it merged (simulate the review with teammate merge fix-typo), update your local main, and delete the local branch.