r/ExperiencedDevs • • Aug 19 '25

Never commit until it is finished?

How often do you commit your code? How often do you push to GitHub/Bitbucket?

Let’s say you are working on a ticket where you are swapping an outdated component for a newer replacement one. The outdated component is used in 10 different files in your codebase. So your process is to go through each of the 10 files one-by-one, replacing the outdated component with the new one, refactoring as necessary, updating the tests, etc.

How frequently would you make commits? How frequently would you push stuff up to a bitbucket PR?

I have talked to folks who make lots of tiny commits along the way and other folks who don’t commit anything at all until everything is fully done. I realize that in a lot of ways this is personal preference. Curious to hear other opinions!

79 Upvotes

315 comments sorted by

View all comments

508

u/iamquah Sr. ML Engineer (6 YOE) -> PhD student Aug 19 '25

I commit every time I make a logical “chunk” of changes and remember to push when I move from my laptop to my desktop. I don’t really see the point of being precious with commits when I can just go back later and squash them. 

140

u/SpiderHack Aug 19 '25

This is why I'm in favor of merges being squashes, cause I make dozens of "added logging" commits in hard bug tickets.

No reason at all to flood the gitlog with that nonsense, but as a dev that IS a logical chunk worth saving

66

u/potchie626 Software Engineer Aug 19 '25

We have rules set that our PRs can only be set to squash into the main branch.

60

u/Poat540 Aug 19 '25

Yeah exactly - devs do lots of commits - then squash into main - 100% the way

28

u/[deleted] Aug 19 '25

Just interactive rebase before you commit to clean up the commits.

100% the way.

25

u/Poat540 Aug 19 '25

Our team has never needed to rebase and our history is linear and clean

39

u/Illustrious-Wrap8568 Aug 19 '25

Linear and clean maybe, but the commits themselves are very likely not atomic, which means you lose a lot of granularity in why certain changes happened. Most people might as well have stayed on svn

11

u/[deleted] Aug 19 '25

If that is the case your PRs are too big.

19

u/Illustrious-Wrap8568 Aug 19 '25

Well, a pull request is a request to merge a branch into another. A PR can absolutely consist of a couple of sensibly formed commits that doesn't need squashing. I am of the opinion that if squash commits need to be the default, you really haven't been curating your commits properly. It also doesn't really encourage people to actually care about their actual commits.

→ More replies (7)

7

u/[deleted] Aug 19 '25

It’s funny how people downvote you, like this is some outrageous statement. How dare you suggest having a clean commit history?

5

u/DefinitelyNotAPhone Aug 19 '25

Why does a clean commit history matter if you're squash merging into your main branch? Doubly so if you need to push up to a pull request so your CI can run tests and spin up development environments, which means you'd need to clean up git history in multiple places.

0

u/[deleted] Aug 19 '25

[deleted] — view deleted comment

→ More replies
→ More replies (5)
→ More replies (1)
→ More replies (2)
→ More replies (3)

4

u/RandomNPC Aug 19 '25

I don't like having this as a rule because there are times where you want different commits. Probably not a problem for many codebases but for ours our commits can sometimes be thousands of files. That way we can break up the "this is just asset updates" commits from the code/logic changes.

Sure we could do them as separate PRs but the tests need both.

3

u/ub3rh4x0rz Aug 20 '25 edited Aug 21 '25

Tbh there's rarely a point in squash merging other than concealing deficiencies in the team's git fu. Just require merge commits, that logically groups the work. I prefer git bisect to be useful, among other benefits of preserving the granularity of history

→ More replies (7)

14

u/Venthe Systems Designer, 10+ YOE Aug 19 '25

This is why I'm in favor of merges being squashes

As long as they are atomic. In my experience, most of them aren't; so squashes are ultimately very detrimental to the git history and futureproofing the application.

I really wish people would learn git beyond three commands.

39

u/difudisciple Aug 19 '25

If we’re talking about the main branch, squashing (ala linear history) makes bisecting issues and rollbacks much easier to manage.

If you need more granularity that that, then work should be split into smaller PRs

4

u/GodsBoss Aug 20 '25

If we’re talking about the main branch, squashing (ala linear history) makes bisecting issues and rollbacks much easier to manage.

We had this exact discussion in our team a few days ago. How does it improve bisecting if the commit I find is a squash commit and does contain more code than a non-squashed commit?

Not sure about the rollback thing. Do you mean reverting to a previous state?

→ More replies (1)

14

u/PabloZissou Aug 19 '25

Wait so let's say I have

  • add user creation
  • add user edit
  • fix flaky user test
  • fix edge case for user
  • PR feedback
  • add user search
  • fix user creation again
  • PR feedback II
  • fix test

Is better than having a single commit in the main branch

  • feature: user management

?

What's the value of the intermediate commits? Why fix with local squash when you can land a full feature into the main branch after review and all is ready for release?

6

u/Venthe Systems Designer, 10+ YOE Aug 19 '25

I'll just drop the resource, it explains it way better than I would do anyway.

https://cbea.ms/git-commit/

In short, I'd probably fixup-rebase that history to ~3 commits. Add user search, add user edit, add user creation. The rest would be squashed/fixup'ed

10

u/PabloZissou Aug 19 '25 edited Aug 19 '25

What's the value of the intermediate commits that on their own have little value?

Edit: I think you are missing the point is not about writing good commit messages is about the lack of value of keeping commit history for intermediate commits which if anything making scanning main or feature branches slow and, if needed, git bisect slower. But well I guess it's a matter of what is valued on each project.

→ More replies (8)
→ More replies (6)

6

u/imagei Aug 19 '25

I agree with the sentiment, but what are you suggesting exactly ?

→ More replies (17)
→ More replies (2)
→ More replies (6)

18

u/Headpuncher Aug 19 '25

Yep, just use commits like auto-save in google docs.   I want VERSION CONTROL not a fucking mystery to solve a week or a year from now.    

The remote feature branch is getting deleted later when merged into main, it’s not costing anyone anything. 

4

u/coitus_introitus Aug 19 '25

Yeah this is the way. If I wind up with questions or I need to troubleshoot something it's just so much easier to handle when I can roll back and forth between a bunch of tiny commits within the larger change.

5

u/mwax321 Aug 19 '25

Plus you can take advantage of commit text and tools like gitlens to give yourself a layer beyond comments in code. For me, comments should explain how it currently works, and the commit/gitlens notes should explain WHY/WHAT changed

2

u/wormhole_bloom 9 YOE Dev Aug 19 '25

my bits: I recommend pushing often because you never know what can happen with your machine and loose your work, specially if you're spending weeks on something, even if you're not changing from laptop to a desktop like you said

other than that 100% agree

→ More replies (5)