When developing something new, I make tons of tiny work-in-progress commits, sometimes dozens in a day, and frequently go back and squash them with rebase into a logical flow of changes, once it's more clear what that logical flow really is. I keep my WIP branches around locally for a while so I can go back and dig out the experiments I made along the way. I prefer this over trying to get every commit right the first…
Ask HN: How often do you commit / push in Git?
21–30 of 36 posts
Re: Ask HN: How often do you commit / push in Git?
#22Re: Ask HN: How often do you commit / push in Git?
#23Re: Ask HN: How often do you commit / push in Git?
#24How often do you press "Save Game" during a new level?
Re: Ask HN: How often do you commit / push in Git?
#25Re: Ask HN: How often do you commit / push in Git?
#26Here's the code in case you wanted to use it:
savework()
{
if git diff --exit-code --quiet
then
echo "There are no changes to save, NONE!";
else
echo "Stage everything for commit -------------";
addit; # an alias for "git add -A ."
echo "Commit all changes with message $@ --------------";
commit "$@"; #commit is an alias for "git commit -m"
echo "Push branch to remote --------------"
psh; # an alias for git push origin $(git branch | grep "*" | sed "s/* //")
fi
}Use it like this: savework "COMMIT MESSAGE HERE"
Re: Ask HN: How often do you commit / push in Git?
#27I 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…
saveallwork "commit message" --ignore "somedir/skipme.too"
I usually have just 1 or 2 files I don't want to include in a commit, but thank you again, it will definitely shave a few mins here and there.
Re: Ask HN: How often do you commit / push in Git?
#28I'm not sure there's a generalizable pattern there for which has a lower actual time interval between commit/pushes but I suspect that I tend to be spammier with them in personal projects.
Re: Ask HN: How often do you commit / push in Git?
#29push and push regularly, in case you have merge conflicts. Get the continuous integration server building on commits and please have it email the team when the build fails too.
Re: Ask HN: How often do you commit / push in Git?
#30Working on something that will take a week to be atomically complete and testable? (For instance, a major refactoring.) I'll write myself a checklist of steps and commit every time I complete a step.
As someone else said, once every 30 sec is too often, and once a day is too infrequent if you're coding 8 hours a day. When I'm in a rhythm I'll typically go anywhere from 10 min to 2 hours between non-trivial (e.g. typo-fix) commits.
I do not push every commit immediately. Once a day is a good minimum as a backup strategy and if you want to make sure you can work on the codebase from elsewhere or if you have a CI system to warn you of merge conflicts.
I'll also push whenever I complete a ticket (for long-running branches we typically have sub-tickets, or I'll push when I've completed work that someone I'm sharing the branch with can build on.) Git makes it easy to develop those units of work on separate branches, and when you merge them back to the feature branch is generally a good time to push.