r/git • u/TachikawaKan5241 • 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
View all comments
Show parent comment
0
u/kpg_on_ao3 19h ago
why would you commit a WIP? A commit is a save point. Why would you want to revert back to broken code?
You should pick a single task/unit of work and implement it. Then commit. My current project, here's the previous few commits:
Each commit compiles, passes all tests, lints, etc., and they all implement one small thing completely. The messages cross-reference tickets, identify if it's a feature or a bug fix or other (chore/refactor/etc.), and often they identify which piece of the code base this commit is about.
Anyone can see from the history what a commit does, and if you look, they usually only involve a couple files. It's easy for anyone to look at and understand quickly.
Keep your commit history clean!