AI Hints
Home›Git & GitHub Tutorial›Comparing Branches
Git & GitHub · Lesson 52 of 144

Practice: An Experiment

Try, then throw away.

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

Not every idea works out. Branches make failed experiments painless. Let's try a wild idea on a branch, decide we don't like it, and throw it away, without main ever knowing.

Practice: An Experiment
From the video: Practice: An Experiment
  • Not every idea works
  • Branches make failure painless
  • Try it, then throw it away

The experiment

We create a branch called rainbow, and commit some very colourful styles. Then we compare it with main. One commit, and the whole difference is visible. We look at it, and decide it's just too much.

git
git switch -c rainbow
Switched to a new branch 'rainbow'
echo 'body { background: linear-gradient(red, orange, yellow, green, blue); }' >> style.css
git commit -am "Try rainbow background"
[rainbow 2380e5a] Try rainbow background
 1 file changed, 1 insertion(+)
git log --oneline main..rainbow
2380e5a (HEAD -> rainbow) Try rainbow background

Throwing it away

So we switch back to main, and delete the branch with capital D, because it was never merged. The experiment is gone, and main's history is exactly as it was. Nobody would ever know.

git
git switch main
Switched to branch 'main'
git branch -D rainbow
Deleted branch rainbow (was 2380e5a).
git log --oneline -n 2
f63a17a (HEAD -> main) Link to about page
ef9c947 Add basic styles

Summary

Experiment on a branch, compare with main, and delete it if you don't like it. Next, we go online, with GitHub.

Key takeaways
  • Experiments on branches
  • Compare, then decide
  • git branch -D to discard
Next up: What GitHub Does — your code, online