r/git • • 3d 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

13 Upvotes

88 comments sorted by

View all comments

1

u/Lion2471 3d ago edited 3d ago

Here's what I did during my software development career.

In the long term, I wanted one commit per bug or feature. By "feature", I generally mean the smallest piece of new functionality that can be coded and tested before being used as a base for the next change. For instance, in software that presents a panel to the user, one feature might simply add a text box with a label to the panel. The next feature might add the logic that processes whatever the user types in that text box when the panel is submitted.

While working on a bug or feature, I made very frequent work-in-progress commits on my own branch, usually multiple times per hour, to avoid any chance of losing my work. Once the bug or feature was done, then I squashed those WIP commits into the one long-term commit that I wanted. To be clear, unlike with the long-term commits, there's no rule that WIP commits need to compile cleanly, as they didn't affect anyone else.