Foundation project
Project: ship a feature on a branch
Lesson 12 of 20 · 14 min · Module 3: Branches
Time to put the local workflow together, the way you will use it every day: a branch for the feature, small commits, a merge, and a tidy finish.
Start this lesson →Free. No installation: you write and run the code in your browser, and it is checked automatically.
By the end, you’ll be able to…
- Plan a feature as a branch with focused commits
- Check each commit before you make it
- Merge and clean up
The idea
Plan first. A new projects page is one feature, so it gets one branch. It has two parts, the page and the menu entry, so it gets two commits. When it is done, merge it into main and delete the branch. Use git status and git diff along the way to check each step.
git switch -c projects-page
git add projects.md
git commit -m "Add a projects page"
git switch main
git merge projects-page
01Plan the branch and the commits
Name the branch after the feature, such as projects-page. Decide what each commit will contain before you start: here, one commit for the page and one for the menu entry.
02Check before every commit
git diff shows what you changed; git status shows what is staged. git commit -am stages and commits every change to tracked files in one step, but it never adds new files.
git switch -c projects-page
echo "Projects" >> menu.txt
git diffSwitched to a new branch 'projects-page'
diff --git a/menu.txt b/menu.txt
index 19036ac..f27620c 100644
--- a/menu.txt
+++ b/menu.txt
@@ -1,2 +1,3 @@
Home
About
+Projects03Merge and tidy up
Back on main, merge the branch. Because main has not moved, it is a fast-forward. Then delete the branch: its commits are now part of main.
git commit -am "Link the projects page from the menu"
git switch main
git merge projects-page[projects-page ac8a404] Link the projects page from the menu
1 file changed, 1 insertion(+)
Switched to branch 'main'
Updating 4abfd2a..ac8a404
Fast-forward
menu.txt | 1 +
1 file changed, 1 insertion(+)Your project brief
projects-page. Commit projects.md, starting with the heading # Projects and with at least one more line, as one commit. Add Projects as the last line of menu.txt in a second commit. Merge the branch into main, delete it, and finish on a clean main.What the checks look for
- main has projects.md with a Projects heading
- The menu on main ends with Projects
- The page and the menu entry are separate commits
- The work happened on projects-page and was merged into main
- The branch is gone and main is clean
Take this with you
Branch, commit in small steps, merge, delete: the everyday Git workflow.
Go a little further
Before merging, run git log --oneline main..projects-page to list exactly the commits the merge will bring in.