One Feature, One Branch
Most teams keep main working and deliver each change on its own short-lived
branch. The branch lets a change be shared, reviewed and finished without
holding anyone else up, and it disappears once its work is on main. This
lesson puts the module's commands together into that routine.

The Routine
-
Branch from an up-to-date main.
git switch main,git pull, thengit switch -c <branch>with a name that says what the change is. -
Commit small, focused changes, each with a message that says what and why.
git commit -m "<summary>" -m "<why>"adds the reason as a body. -
Share the branch with
git push -u origin <branch>, so others can see it and it is backed up. -
Keep it current. If
mainmoves on, pullmain, then merge it into your branch so you test against the latest work. Because the branch is shared, merging is safer than rebasing. -
Integrate. Switch to
main, pull, merge the branch and push. On many teams this step happens through a review on a hosting service, which the optional module covers. -
Clean up. Delete the branch locally with
git branch -dand on the remote with:git push origin --delete <branch>Teammates' clones still remember the old remote branch.
git fetch --pruneremoves remote-tracking branches whose branch is gone from the remote.
Making Changes Easy to Review
Before you ask someone to look at a branch, make it easy to understand:
- Small scope: one feature or fix per branch. A branch that also renames files and reformats code is hard to check.
- Clear history: focused commits with meaningful messages; tidy "wip" commits before sharing, as in the rebase module.
- A description of why: what problem the change solves and anything a reviewer should check. The commit body is a good place to start.
Exercise: Deliver Two Features Through the Shared Remote
Asha adds a FAQ page and Ravi a contact page, each on a branch, and both reach
main through shared.git.
Starting state: Git configured as in the configuration lesson. You will rebuild the team practice set, and remove it at the end of this lesson.
-
Rebuild the practice set:
cd ~/git-practice rm -rf team mkdir team cd team git init --bare -b main shared.git git clone shared.git asha cd asha git config user.name "Asha Rao" git config user.email "asha@example.com" cat > README.md <<'EOF' # Team notes We meet on Mondays. Bring your laptop. EOF git add README.md git commit -m "Add team notes" git push -u origin main cd .. git clone shared.git ravi cd ravi git config user.name "Ravi Kumar" git config user.email "ravi@example.com" cd .. -
As Asha, start the FAQ on a branch and share it:
cd asha git switch main git pull git switch -c add-faq cat > faq.md <<'EOF' # Questions new members ask Where do we meet? Room 4. What should I bring? Your laptop. EOF git add faq.md git commit -m "Add a FAQ page" -m "New members ask the same questions every week." git push -u origin add-faq -
As Ravi, start the contact page the same way:
cd ../ravi git switch main git pull git switch -c add-contact cat > contact.md <<'EOF' # Contact Message Ravi with questions about the meetings. EOF git add contact.md git commit -m "Add a contact page" -m "People keep asking who organises the meetings." git push -u origin add-contact -
As Asha, integrate the FAQ and clean up:
cd ../asha git switch main git pull git merge add-faq git push git branch -d add-faq git push origin --delete add-faqThe merge fast-forwards, because
mainhad not moved. The last command reports- [deleted] add-faq. -
As Ravi, bring the new
maininto the contact branch:cd ../ravi git switch main git pull git switch add-contact git merge --no-edit main git pushThe branch now contains the FAQ as well, so Ravi can check that his page works with it.
-
As Ravi, integrate the contact page and clean up:
git switch main git merge add-contact git push git branch -d add-contact git push origin --delete add-contact git log --oneline --graph -
As Asha, catch up and remove stale names:
cd ../asha git fetch --prune git pull git branch -a git log --onelinegit fetch --prunereports- [deleted]fororigin/add-contact.git branch -alists onlymainandorigin/main, and possiblyorigin/HEAD, a pointer to the remote's default branch. The log contains both features.
Success: both features are on main in shared.git, and the finished
branches are gone from both clones and from the remote.
If something differs:
| What you see | Likely cause | Next step |
|---|---|---|
git branch -d says is not fully merged | The branch was not merged into the branch you are on | Switch to main, merge, then delete |
remote ref does not exist | The remote branch was already deleted | Nothing to do; run git fetch --prune |
Old branches still listed under remotes/origin | The clone has not pruned | git fetch --prune |
| The push in step 4 or 6 is rejected | The other collaborator pushed first | git pull, then push again |
Independent task: as Ravi, deliver one more small feature from start to
finish: a directions.md page saying how to find Room 4. Use a branch and a
commit message with a body that explains why, share the branch, integrate it
into main and clean it up everywhere. Then show from Asha's clone that
main has the page and no feature branch is left anywhere.
-
Remove the whole practice set. This module is finished:
cd ~/git-practice ls rm -rf team ls
Check Your Understanding
A teammate opens a branch for review called updates with 23 commits. It adds
a new booking form, renames half the files in the project and fixes a typo on
the home page. Most commit messages say "wip" or "more changes", and there is
no description. List what makes it hard to review, and how you would improve
it.
Answer and Reasoning
Independent task
In ravi:
git switch -c add-directions
cat > directions.md <<'EOF'
# Directions
Room 4 is on the first floor, next to the library.
EOF
git add directions.md
git commit -m "Add directions to Room 4" -m "Two new members got lost last week."
git push -u origin add-directions
git switch main
git pull
git merge add-directions
git push
git branch -d add-directions
git push origin --delete add-directions
Then in asha:
git fetch --prune
git pull
git branch -a
git log --oneline -1
Asha's newest commit is "Add directions to Room 4", and git branch -a lists
no feature branches, locally or under remotes/origin.
Understanding check
- Too much scope: three unrelated changes in one branch. Split them into separate branches: the booking form, the renames and the typo fix.
- Vague name:
updatessays nothing;add-booking-formwould. - Unclear history: 23 commits labelled "wip" make it impossible to follow the reasoning. Tidy them into a few focused commits before sharing.
- No description: a reviewer cannot tell what problem the change solves or what to check. Explain why in the commit bodies and in the request for review.