Black Friday: the Laravel testing course is $149 instead of $249, through Dec 7. See the course →
logo

Always use a branch

No really, always

Joel Clermont
Joel Clermont
2025-02-05

From our daily Laravel tips email. Get the next one in your inbox.

When Aaron and I are pairing, sometimes he'll say something that just slaps me across the face.

Recently, I had that experience when we were planning out an upcoming feature, and there was an unresolved question as to how the feature currently worked.

After opening the code in question, and talking it through, there was still a little bit of uncertainty around a particular edge case, and as I was trying to figure it out, Aaron stopped me and said "Just write a test."

He was right. Why waste another brain cell on trying to predict the flow of code in this edge case, just write the test.

But that wasn't the insight I want to share today (although it is another good insight to share). Instead, when I opened the test and wrote out the new test method, Aaron said "Hey what are you doing? You're on main. You should be on a branch."

I initially resisted. This was exploratory code I was going to throw away. But pretty quickly, I realized he was right.

First, even if I plan on throwing it away, then I can just delete the branch. And I avoid accidental commits to main if I forget or get distracted with something else before cleaning it up.

And as it turned out in this case, once we wrote the test covering the edge case question, why wouldn't we keep it? It adds to knowledge of the application and gives us better test coverage. Now it's in a branch, which I can push up and open a pull request for review.

Here to help,

Joel

P.S. You got two tips today for the low, low price of $0. If you want to help support my writing and get access to even more valuable insights, join the Mastering Laravel community.

Want a tip like this in your inbox every weekday?

Each one takes less than 2 minutes to read. Join 4,000+ Laravel developers who already get them.

email
No spam. Only real-world advice.
Toss a coin in the jar if you found this helpful.