Why You Should Keep Your Commits Under 300 Lines

I've been spending most of my October so far creating issues and reviewing code.

And one thing that I always tell newcomers is to keep their PRs small.

300 lines is an arbitrary number, but the point is to keep it small.

Here's why:

Easy to Understand

Imagine reading a book where each chapter is 300 pages long. It's hard to understand, right? Similarly, smaller commits are easier to read and grasp. When you make changes, your teammates will thank you for giving them bite-sized pieces to review.

Quick Reviews

Larger commits can be overwhelming. It's like asking someone to review an entire novel in one go! Smaller commits mean faster reviews. Your team can quickly identify issues and move forward.

Simplified Bug Tracking

If something goes wrong, smaller commits make it easier to identify the culprit. With bigger commits, it's like searching for a needle in a haystack. Small commits make the haystack manageable!

Better Commit Messages

With smaller changes, you can write more specific commit messages. Instead of saying, "Fixed bugs", you could say, "Fixed login bug by updating authentication method." It's clearer and more helpful. Especially when looking over history.

Encourages Good Habits

When you aim for smaller commits, you naturally divide your tasks into manageable chunks. This improves focus and promotes a systematic approach to problem-solving.

Flexibility in Reverting

Mistakes happen. If you need to undo a change, it's easier with smaller commits. Imagine trying to untangle a massive knot versus a small one. Which would you prefer?

Merges and Conflicts

Smaller commits reduce the chances of conflicts when multiple people work on the same code. If conflicts do occur, they're easier to resolve.

Better Collaboration

Clear, concise commits promote collaboration. When your team understands your changes quickly, they can build upon them or give valuable feedback.

Remember, 300 is just a number I tend to enforce on my teams, but what it's really about is clarity, efficiency, and collaboration.

Adopt this habit, and watch your coding process transform for the better!

GitTipsProductivityDeveloper Tips
Avatar for Niall Maher

Written by Niall Maher

Founder of Codú - The web developer community! I've worked in nearly every corner of technology businesses; Lead Developer, Software Architect, Product Manager, CTO and now happily a Founder.

Loading

Fetching comments

Hey! 👋

Got something to say?

or to leave a comment.