AI Hints
Home›Git & GitHub Tutorial›Project: Hotfix
Git & GitHub · Lesson 130 of 144

Project: An Urgent Fix

A hotfix for v1.0.

⏱ 2 min read▶ Video at 2:21:43🎓 Free
Watch this lesson in the Git & GitHub courseWatch on YouTube ↗Full Git & GitHub course

Here's a classic real-world situation. Version one point oh is live. Main already has new, unfinished work for the next version. Then someone reports a broken link on the live site. You need to fix version one point oh, without releasing the unfinished work.

Project: An Urgent Fix
From the video: Project: An Urgent Fix
  • v1.0 is live
  • main has unfinished work
  • A bug needs fixing now

Where things stand

The graph shows the v one point oh tag, and one newer commit on main, the shop page, which isn't ready. If we fixed the bug on main and released it, the unfinished shop would go live too.

git
git log --oneline --graph -n 3
* 2cb1565 (HEAD -> main) Start shop page (not ready)
* b5a503b (tag: v1.0, origin/main) Tidy home page
* f63a17a Link to about page

Branch from the tag

So we create a branch from the tag itself. Git switch dash c, hotfix slash about link, v one point oh. Now our files are exactly as they were in version one point oh. The shop page isn't here.

git
git switch -c hotfix/about-link v1.0
Switched to a new branch 'hotfix/about-link'
ls
about.html
index.html
style.css

Fix only the bug

In our editor, we fix the link, which was missing the L at the end, and nothing else. A hotfix should be as small as possible. Diff shows the one line we changed. Then we commit it.

git
git diff
diff --git a/index.html b/index.html
index 0fcb72d..93dd595 100644
--- a/index.html
+++ b/index.html
@@ -1,3 +1,3 @@
 <h1>My Site</h1>
 <p>Welcome!</p>
-<a href="about.htm">About</a>
+<a href="about.html">About</a>
git commit -am "Fix broken About link"
[hotfix/about-link 684c1a8] Fix broken About link
 1 file changed, 1 insertion(+), 1 deletion(-)

Summary

To fix a released version, create a branch from its tag, not from main. Next, releasing the fix.

Key takeaways
  • Tag = the released code
  • git switch -c hotfix/x v1.0
  • Fix only the bug
Next up: Project: Releasing v1.0.1 — tag the fix