Live data from Hacker News

Ask HN: How often do you commit / push in Git?

news.ycombinator.com

31–36 of 36 posts

Re: Ask HN: How often do you commit / push in Git?

#32

I use feature branched for everything, usually named after an issue number. I created a script that allows me to commit whenever I get a task done, not the whole feature, and that script takes care of adding the files, committing them with a message, tags it with the issue number (current branch name), and pushes to remote. That way, every time I save, the changes are saved on the remote GIT repo in case my computer…

That seems like it could generate an excessive amount of commits (or maybe not everyone saves hundreds of times per day).

Just curious -- do you squash commits when merging one of these feature branches?

Re: Ask HN: How often do you commit / push in Git?

#33
I find it varies with the work being done vs. relating to a discrete time duration.

In general, I try to be very atomic. As an added benefit, this makes it simpler for someone doing a git bisect later.

Fixing minor typos or copy changes across a few files could result in several commits within 15 minutes.

Working on a major feature that requires research and definition and a lot of conversation or feedback, might mean a few commits over the span of a few days.

Re: Ask HN: How often do you commit / push in Git?

#34
Only once so far: https://github.com/git/git/commit/75d2e5a7b038debee406805c9e... is my git commit ;-)

But seriously, I commit regularly, and rebase locally before pushing, whenever possible.

It's not really about how often you commit, it's about documenting that commit as a single unit of work so looking at it it's clear what you did, and why. This often requires planning ahead of time, and even possibly creating a separate branch just for off topic commits that you think of while working on the same file.

I'm not perfect though, it's okay not to be perfect.

Re: Ask HN: How often do you commit / push in Git?

#35
> and hired an external consultant to get in order.

Recipe for disaster. :p

> knew people who pushed / committed like every 30 seconds

Pushing and committing is completely different actions in the git world.

If it's a simple fix then I try to commit and push almost instantly. If it is a large piece of work that needs several days, then I "checkpoint" it by committing at least once/day.

But I try to never checkpoint by committing something that breaks the build or unit tests. Like if my work is rewriting module A to B, then my first commit would be to add module B, second to change all dependencies from A to B and lastly to delete module A from the repo.

Post reply on HN