r/git • • 1d ago

How often should I commit my changes?

I am fairly new to programming and git and I was just wondering how often I should commit my changes both locally and to Github? I feel like I'm doing it to often

9 Upvotes

79 comments sorted by

View all comments

Show parent comment

1

u/symbiatch 18h ago

You literally answered your own question.

“A commit is a save point.”

That doesn’t mean it’s working correctly. It’s a point. “Here I made part 1 work, everything else isn’t working” is a save point. It’s broken since it doesn’t work fully, but it’s reasonable to save it.

Why would I want to revert to that? Because part 1 works. I broke rest more. Not working, let’s go back and do differently.

And then you even list how you commit “broken code.”

You also seem to confuse this with pushes and merges which are entirely different thing.

1

u/themule71 6h ago

Yeah u/kpg_on_ao3 seems to have missed the "rebase & squash" part. That's what leaves the history "clean".

Only on demos or very simple apps the units of work are small enough to be truly independent... in real, complex cases there can be multiple moving parts (think backend, frontend, APIs), often multiple developing teams, all working on the same feature. One can complete via stubs. One implementation may need refactoring later due to performance reasons that are not evident until all pieces are put together. Yet there can be a moment when "ok, our part is done for now, let the other teams see it", that doesn't mean it's the final implementation, it may turn out to be broken, incomplete, sub-optimal, etc.

A commit, even push to a wip branch, is something I want others to see, broken or not I don't know yet.

As I wrote in another comment, you final git history should be as clean as possible to enable git bisec.