DEV Community

C. Leovido
C. Leovido

Posted on

One Git Command That Saved My Sanity (And Thousands of Conflict Resolutions)

Hey, I'm starting with a quick dev tip that's been a game-changer for my workflow lately.

If you've been working in a team, you know the drill: you create a feature branch, make progress, add commits... and then, it's time to rebase against main.

You know what's coming, right? That moment when Git starts replaying each of your 9 commits one by one, and you're resolving the same conflict over and over again.

That's painful.

Sure, GitHub has that "squash and merge" button that'll compress everything into one commit. Great for merge time.

But what about before you merge?

What happens when you need to rebase your branch first because main has moved forward?
You're stuck in conflict resolution hell.

The Classic Approach (And Why It's Still a Hassle)

Most of us know about interactive rebase:

git rebase -i HEAD~9
Enter fullscreen mode Exit fullscreen mode

This opens an editor where you mark commits to squash or fixup. It works!

But it's a lot of steps: count your commits, edit the file, save, resolve conflicts at each step if they show up. I used to do this all the time until I discovered something way simpler.

The One-Command Alternative

Here's what I've been using instead, and honestly, it's changed how I handle messy branches:

git reset --soft main && git commit -m "feat: implement user authentication"
Enter fullscreen mode Exit fullscreen mode

What's happening here?

git reset --soft main rewinds your branch pointer back to main, but keeps all your changes staged

All your commits since you branched off? Gone. But your actual code changes? Still there, ready to commit
You create one clean commit with all your work

Why This Matters

When you rebase now, Git only replays one commit instead of nine. One commit = one potential conflict to resolve, not nine separate conflict sessions.

This has saved me hours.

When to Use This (And When Not To)

✅ Use it for:

  • Cleaning up your feature branch before rebasing
  • Consolidating "WIP" or experimental commits
  • Making your branc h easier to review

⚠️ Don't use it when:

  • Your branch is already pushed and teammates have based work on it (you'll need to force-push)
  • The commit history actually tells a valuable story worth preserving
  • You're contributing to open-source with strict history requirements

A Word of Caution

This rewrites your commit history, so you'll need to force-push afterward. I always use --force-with-lease instead of --force to avoid accidentally overwriting work:

git push --force-with-lease
Enter fullscreen mode Exit fullscreen mode

And only do this on branches you own. Don't mess with shared history!

Your Turn

This technique has become part of my daily workflow. It's one of those small things that compounds over time, saving mental energy and keeping my git history clean.

What about you? Do you stick with interactive rebase? Use squash merges? Something else entirely? I'd love to hear what works for your team.

Drop a comment below or find me on https://farcaster.xyz/leovido.eth

Top comments (0)