<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: arrow dan</title>
    <description>The latest articles on DEV Community by arrow dan (@arrowdan).</description>
    <link>https://dev.to/arrowdan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F710767%2Ffdf663b0-a64d-4a8d-a909-28f5353dad2e.png</url>
      <title>DEV Community: arrow dan</title>
      <link>https://dev.to/arrowdan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/arrowdan"/>
    <language>en</language>
    <item>
      <title>🔄 Git Squashing: How to Clean Up Your Commit History Like a Pro</title>
      <dc:creator>arrow dan</dc:creator>
      <pubDate>Sat, 24 May 2025 09:11:45 +0000</pubDate>
      <link>https://dev.to/arrowdan/git-squashing-how-to-clean-up-your-commit-history-like-a-pro-5h27</link>
      <guid>https://dev.to/arrowdan/git-squashing-how-to-clean-up-your-commit-history-like-a-pro-5h27</guid>
      <description>&lt;p&gt;As software engineers, we often make multiple small commits during development — and that’s okay. But when it’s time to merge a feature branch into your main codebase, a messy commit history can make things harder to read, debug, and review.&lt;/p&gt;

&lt;p&gt;That’s where Git squashing comes in.&lt;/p&gt;

&lt;p&gt;In this article, I’ll walk you through what Git squashing is, why it matters, and how to do it cleanly, even if you have untracked changes.&lt;/p&gt;

&lt;p&gt;🧠 What Is Git Squashing?&lt;br&gt;
Git squashing is the process of combining multiple commits into a single, cleaner commit. It’s especially useful when you’ve made several “work-in-progress” (WIP) commits that aren’t meaningful on their own.&lt;/p&gt;

&lt;p&gt;For example, instead of these commits:&lt;/p&gt;

&lt;p&gt;✔️ Create login form&lt;br&gt;&lt;br&gt;
✔️ Fix typo&lt;br&gt;&lt;br&gt;
✔️ Add missing styles&lt;br&gt;&lt;br&gt;
✔️ Adjust padding&lt;br&gt;
You can squash them into:&lt;/p&gt;

&lt;p&gt;✔️ Create login form with styles and fixes&lt;br&gt;
This keeps the project history tidy and professional — making life easier for reviewers and your future self.&lt;/p&gt;

&lt;p&gt;✨ When Should You Squash?&lt;br&gt;
Before merging a feature branch into main or develop&lt;br&gt;
After exploratory coding that involved many small changes&lt;br&gt;
When preparing pull requests for clean code reviews&lt;br&gt;
🛠️ How to Squash Commits in Git&lt;br&gt;
Let’s say you made 3 commits on your feature branch that you want to squash:&lt;/p&gt;

&lt;p&gt;git log --oneline&lt;br&gt;
a3f1c7f Fix button spacing&lt;br&gt;&lt;br&gt;
b7d2f1c Add button styles&lt;br&gt;&lt;br&gt;
c4a1e90 Create button component&lt;br&gt;
✅ Step 1: Start the interactive rebase&lt;br&gt;
git rebase -i HEAD~3 # The last 3 commits the from HEAD.&lt;br&gt;
This tells Git you want to rebase the last 3 commits.&lt;/p&gt;

&lt;p&gt;✅ Step 2: Mark commits to squash&lt;br&gt;
Git opens an editor (like Nano or Vim). You’ll see something like:&lt;/p&gt;

&lt;p&gt;pick c4a1e90 Create button component&lt;br&gt;&lt;br&gt;
pick b7d2f1c Add button styles&lt;br&gt;&lt;br&gt;
pick a3f1c7f Fix button spacing&lt;br&gt;
Change the second and third lines from pick to squash:&lt;/p&gt;

&lt;p&gt;pick c4a1e90 Create button component&lt;br&gt;&lt;br&gt;
squash b7d2f1c Add button styles&lt;br&gt;&lt;br&gt;
squash a3f1c7f Fix button spacing&lt;br&gt;
Save and exit (CTRL + O, Enter, then CTRL + X in Nano) Or a shorter way is CTRL S(save) and CTRL X(exit)&lt;/p&gt;

&lt;p&gt;✅ Step 3: Edit the final commit message&lt;br&gt;
Git will prompt you to write a new commit message. You can combine or simplify the existing messages:&lt;/p&gt;

&lt;p&gt;Create button component with styles and spacing fixes&lt;br&gt;
Save and quit.&lt;/p&gt;

&lt;p&gt;✅ Result: One Clean Commit!&lt;br&gt;
Now when you run:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;git log --oneline&lt;/em&gt;&lt;br&gt;
You’ll see:&lt;/p&gt;

&lt;p&gt;abc1234 Create button component with styles and spacing fixes&lt;br&gt;
A single, clean commit that reflects the real purpose of your work.&lt;/p&gt;

&lt;p&gt;📤 What About Pushing to GitHub?&lt;br&gt;
If you haven’t pushed this branch before:&lt;br&gt;
Just push as usual:&lt;/p&gt;

&lt;p&gt;git push origin your-branch&lt;br&gt;
If you already pushed before squashing:&lt;br&gt;
You’ve rewritten commit history, so Git requires a force push:&lt;/p&gt;

&lt;p&gt;git push --force origin your-branch&lt;br&gt;
Or, safer:&lt;/p&gt;

&lt;p&gt;git push --force-with-lease origin your-branch&lt;br&gt;
This makes sure you don’t overwrite changes others may have pushed.&lt;/p&gt;

&lt;p&gt;💡 Bonus: What If I Have Untracked Changes?&lt;br&gt;
No problem. Just stage and commit them after the squash:&lt;/p&gt;

&lt;p&gt;git add .&lt;br&gt;
git commit -m "Handle final UI tweaks"&lt;br&gt;
Then push everything together.&lt;/p&gt;

&lt;p&gt;🧼 Why It Matters&lt;br&gt;
Squashing isn’t just about tidiness — it’s about clarity, professionalism, and respect for your team’s time. Clean commit history makes code reviews easier, debugging faster, and Git blame more helpful. It’s a small practice with a big impact.&lt;/p&gt;

&lt;p&gt;🙌 Final Thoughts&lt;br&gt;
Git is powerful, and squashing is one of its most elegant tools. If you’re working on features that involve lots of intermediate changes, use squashing to present your work in the clearest way possible.&lt;/p&gt;

&lt;p&gt;Make squashing part of your development flow — your teammates (and future you) will thank you.&lt;/p&gt;

&lt;p&gt;🔁 Have thoughts or tips on Git squashing? Let’s connect — drop a comment or share your own Git habits below!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>devops</category>
      <category>python</category>
    </item>
  </channel>
</rss>
