Git Essentials: Stop Breaking the Build

Git Essentials: Stop Breaking the Build

2024-06-04
2 min read

Executive Summary

"You think you know Git, until you have a merge conflict on Friday at 5pm. Rebase vs Merge, Atomic Commits, and how to undo mistakes."

Git Essentials: Stop Breaking the Build

Git is the most important tool you use. You use it every day. Yet, most developers are terrified of it. They memorize 3 commands (add, commit, push) and pray nothing goes wrong.

When things go wrong, they delete the folder and re-clone. We can do better.

Here is what we'll cover:

  1. Atomic Commits: The golden rule of history.
  2. Merge vs. Rebase: The religious war, settled.
  3. The "Safety Net": How to undo anything (reflog).
  4. Squashing: Keeping the history clean.

1. Atomic Commits

Bad Commit: Commit: "Fix stuff"

  • Contains: A bug fix, a new feature, and some CSS changes.
  • Why it's bad: If the bug fix is wrong, I have to revert the CSS changes too.

Atomic Commit: One logical change per commit.

  1. fix(auth): handle null user token
  2. feat(ui): add new button style
  3. refactor(api): clean up routes

If I need to revert the auth fix, I can rely on a clean history.

2. Merge vs. Rebase

  • Merge: Preserves history exactly as it happened.
    • Pros: Honest.
    • Cons: Creates "Spaghetti" history with messy "Merge branch 'master'" commits.
  • Rebase: Rewrites history to look linear.
    • Pros: Clean, straight line. Easy to debug.
    • Cons: Dangerous if you rebase shared branches.

The Professional Workflow:

  1. Rebase locally. (git pull --rebase origin main). Keep your branch up to date.
  2. Squash and Merge into main.

This gives you a linear history on Main, which makes git bisect (debugging) much easier.

3. The "Oh No" Button: Reflog

You accidentally deleted a branch? You reset to the wrong commit? Don't panic. Git never deletes anything immediately.

git reflog

This logs every move you made. Even the ones you undid. Find the hash before you messed up, and git reset --hard <hash>. You are saved.

4. Writing Good Commit Messages

Use the Conventional Commits standard. type(scope): message

  • feat: A new feature.
  • fix: A bug fix.
  • docs: Documentation only.
  • chore: Build process, deps.

Why? You can automate your Changelog. Tools can read these commits and generate: "Version 1.2.0: Added 3 features, Fixed 2 bugs."

Summary

  1. Commit small. (Atomic).
  2. Rebase often. (Keep it linear).
  3. Learn Reflog. (Safety net).
  4. Write meaningful messages. (Be kind to future you).
Interactive Practice Sandbox • Zero Risk

Theory is Good. Muscle Memory is Better.

Don't let your first time handling this scenario be in front of your engineering team or manager. Rehearse your points with our interactive AI personas, get real-time feedback on assertiveness and clarity, and calibrate your approach before it counts.


Written by The DevToLead Team

We are a group of senior engineers and tech leads sharing our real-world experience to help you grow. Our mission is to bridge the gap between junior developers and confident technical leaders.

The Tuesday Leadership Dilemma

One High-Stakes Scenario in Your Inbox Every Tuesday

Rehearse the hardest parts of engineering leadership: tense scope negotiations, defensive 1-on-1s, and architectural stalemates. Complete with suggested diplomatic scripts.

100% FreeNo spam everUnsubscribe in 1 click
Or try the Live AI Simulator