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
1
u/felixnavid 1d ago
A commit has two roles:
Before AI, I have tried to split PRs into smaller commits so that my reviewer can follow my train of thoughts (role 2). Each commit can be built. Maybe tests are separate in the next commit. And during merge, you either squash all commits into one ( GitLab's preffered flow) or just merge all commits as is.
Locally, commit every day ( others said 4 hours), and add some notes for yourself so that tommorrow you can continue. (role 1) You can amend these commits later or squash them so that others can see browse the code logically ( role 2).