Let's Save the (Git) Trees

Published 19 days ago • 2 min read

Hi friends,

You know how companies use merge commits when working on projects?

Just go to one of your work projects and checkout the history of the main branch. It may look tidy (or not) but it’s bad for the environment (the real-world one 😉)

While that’s pretty standard, it actually makes things messy.

Every time we do this, it stops us from keeping our commit history nice and clean all the way through from development to production.

Here’s why that’s a bit of a problem: if we’ve already built and tested a commit, installing dependencies in the process and storing all its details, there’s really no need to go through all that again.

It’s like doing the same work twice, which wastes time and resources, which translate to environmental effects that compound and another financial waste if that’s not enough.

Plus, a cleaner git history makes it easier for us to figure out issues. It helps us use tools like git bisect much more effectively to find bugs. But we’ll talk more about that another time.

So, what’s the solution?

We start using something called interactive rebase on our feature branches. It’s really just a way to clean up our commit history before we merge it into the main branch. This might change the history, but since it’s just on our own feature branches, it doesn’t mess up anything for everyone else.

Here’s a quick guide on how to do it:

  1. Start on Your Feature Branch:git checkout -b my-feature
  2. Grab the Latest Main Branch Updates Without Switching:git fetch origin main:main (using main:main is a trick to fetch remote main changes to the local copy without switching back and forth)
  3. Interactive Rebase Time:git rebase main --interactive - This lets us pick and choose which commits to keep or squash, change the commits you want to s to make sure git squashes them into the parent commit, while keeping the changes.
  4. Safely Update the Remote Branch:git push --force-with-lease - This flag makes sure we don’t accidentally overwrite anyone else’s work.
  5. Prepare to Merge:git checkout main
  6. Merge Without Extra Commits:git merge --ff-only - - Keeps our history straight by avoiding merge commits.
  7. Push it Up:git push - And we’re done!

By making this part of what we do every day, our git trees will stay clean and easy to work with.

Hope you find this helpful! Always happy to hear your thoughts or answer any questions.

Enjoy your weekend!

Whenever you’re ready, here’s how I can help you


Every once in a while I send hand picked things I've learned. Kind of like your filter to the tech internet. No spam, I promise!


Hi Friends, Today, we’re diving into the often under-appreciated git blame. Often used to find out who last modified a line of code, git blame has several powerful features. Let’s explore some of these hidden gems, particularly focusing on the flags: -w -C -C -C -C -C -C blame -C -C -C ignores code movements across the entire history Ignoring Whitespace with the -w Flag Do you know the annoying blame results showing over an indent or a space removed / added? "-w" fixes that! git blame -w...

5 days ago • 1 min read

Hi friends, This is the story of how one mysterious hacker, took advantage of an inactive negligible library in Linux, and the maintainers emotional stress. Slowly, week after week, bit by bit lines of seemingly random testing code were added, in front of everyone’s eyes, to the Linux upstream. Thanks to one curious developer, who had an itch because of a tiny lag in his login process, sending him deep into the rabbit hole of Linux SSH and the mystic world of ZX, we would have never heard of...

12 days ago • 6 min read

Hi friends, If you had asked me about the future of DevOps / infrastructure a few years ago, I would’ve pointed straight to serverless. I don’t think that anymore. After this week’s Kubecon in Paris (amazing event by the way!), here’s a collection of thoughts and prediction on the future of tech. The morning of the 3rd day at Kubecon Paris (21/03/24) While serverless was a big deal, the rise of container technology and Kubernetes has been astonishing, even the biggest advocates of the...

26 days ago • 1 min read
Share this post