Live data from Hacker News

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

news.ycombinator.com

21–30 of 36 posts

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

#21

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…

What is the purpose of committing though? What does it additionally get you that you don't get by working in place without committing?

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

#26
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 dies or something.

Here'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?

#27

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…

Thank you, I'm going to modify it to:

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?

#28
Depends. If it's just the beginning of a project or a side project where I'm definitely the only person working on it then I generally just use it as a backup system. If it's a more substantial project then I try to remember to commit and branch off before embarking on new feature additions, major refactors, or really anything where several hours in you could find yourself cursing and deciding that particular adventure was ill advised or is currently not worth it.

I'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?

#29
check in when it makes sense. In a feature branch? whenever you like as long as it's building often. In a dev branch directly? often enough so change gets into test regularly but not so often that your small change sets break the build our functionality other devs may also be working.

push 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?

#30
I commit every time I complete an atomic unit of work. Write a 3-line test and a 3-line method that passes it? Commit.

Working 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.

Post reply on HN