TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

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

17 pointsby obfuscatedgeekabout 9 years ago
So my company decided to try out the Scrum working methodology and hired an external consultant to get in order. The consultant was giving a talk and basic introduction about Scrum and stuff. He emphasized committing &#x2F; pushing to Git on regular basis and said he knew people who pushed &#x2F; committed like every 30 seconds. In my mind I was going WTF are you talking.<p>How often do you guys commmit &#x2F; push ? I push in my changes when I have completely finished working on a feature &#x2F; module

26 comments

jtfairbankabout 9 years ago
I&#x27;ll commit for small, incremental changes. Each commit is a semantic change to me- could be a small change applied in the same way across multiple files, or a larger change in a single file that does one thing.<p>I tend to push at the first opportunity it makes sense for other people to see my code, and then push again whenever I make enough incremental progress towards the feature to share. Our team has a culture of opening &quot;in progress&quot; PRs early and often to get feedback before we are too far along. This is great to share ideas and feedback about how things should work (instead of just about how they do based on implementation). It also helps keep the final code review size &#x2F; time down.
serenabout 9 years ago
You need at least an atomic change, i.e compiling&#x2F;testing&#x2F;deploying at that point makes sense.<p>If you just updated a typo in some comments, it could make sense to commit it and it could take 30 seconds.<p>Now if you are always committing as frequently, either you are working on very easy tasks with no dependencies, either there is an issue.
cypharabout 9 years ago
I usually commit whenever I&#x27;ve done one thing that builds and is the smallest amount of change that is still a self-contained change. For example, changes to package scripts, the code and test cases all live as separate commits. The most important thing to do is to make sure no commit breaks the build and that the commits are small enough that someone can follow what they are doing when they&#x27;re bisecting in the future.
victorbelloabout 9 years ago
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.<p>Here&#x27;s the code in case you wanted to use it:<p>savework()<p>{<p><pre><code> if git diff --exit-code --quiet then echo &quot;There are no changes to save, NONE!&quot;; else echo &quot;Stage everything for commit -------------&quot;; addit; # an alias for &quot;git add -A .&quot; echo &quot;Commit all changes with message $@ --------------&quot;; commit &quot;$@&quot;; #commit is an alias for &quot;git commit -m&quot; echo &quot;Push branch to remote --------------&quot; psh; # an alias for git push origin $(git branch | grep &quot;*&quot; | sed &quot;s&#x2F;* &#x2F;&#x2F;&quot;) fi </code></pre> }<p>Use it like this: savework &quot;COMMIT MESSAGE HERE&quot;
评论 #11227880 未加载
评论 #11234570 未加载
cauterizedabout 9 years ago
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.<p>Working on something that will take a week to be atomically complete and testable? (For instance, a major refactoring.) I&#x27;ll write myself a checklist of steps and commit every time I complete a step.<p>As someone else said, once every 30 sec is too often, and once a day is too infrequent if you&#x27;re coding 8 hours a day. When I&#x27;m in a rhythm I&#x27;ll typically go anywhere from 10 min to 2 hours between non-trivial (e.g. typo-fix) commits.<p>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.<p>I&#x27;ll also push whenever I complete a ticket (for long-running branches we typically have sub-tickets, or I&#x27;ll push when I&#x27;ve completed work that someone I&#x27;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.
lsiebertabout 9 years ago
Only once so far: <a href="https:&#x2F;&#x2F;github.com&#x2F;git&#x2F;git&#x2F;commit&#x2F;75d2e5a7b038debee406805c9e21a86e7c085789" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;git&#x2F;git&#x2F;commit&#x2F;75d2e5a7b038debee406805c9e...</a> is my git commit ;-)<p>But seriously, I commit regularly, and rebase locally before pushing, whenever possible.<p>It&#x27;s not really about how often you commit, it&#x27;s about documenting that commit as a single unit of work so looking at it it&#x27;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.<p>I&#x27;m not perfect though, it&#x27;s okay not to be perfect.
denniskubesabout 9 years ago
We use a fork model where each developer has their own fork of the &quot;main&quot; repository and the developer fork is cloned to the local dev machine.<p>Using this model I do work in progress commits as needed for different features using many different branches. Those wips and committed locally and are pushed to the remote fork many times per day for backup. For example I can do a quick push before going to lunch or meeting. I can also fetch, rebase, squash, and force push commits as desired because the only history I am affecting is on my own fork. The final merge to the &quot;main&quot; repository is usually 1-2 commits squashed from all the wip commits. Once that is merged I, since I am usually working on a feature branch, I can delete that branch locally and in the remote fork.<p>Every 30 seconds seems like a bit much, but it wouldn&#x27;t be unreasonable to say I commit and push 10x a day.
bjourneabout 9 years ago
&gt; and hired an external consultant to get in order.<p>Recipe for disaster. :p<p>&gt; knew people who pushed &#x2F; committed like every 30 seconds<p>Pushing and committing is completely different actions in the git world.<p>If it&#x27;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 &quot;checkpoint&quot; it by committing at least once&#x2F;day.<p>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 <i>add</i> module B, second to change all dependencies from A to B and lastly to delete module A from the repo.
BWStearnsabout 9 years ago
Depends. If it&#x27;s just the beginning of a project or a side project where I&#x27;m definitely the only person working on it then I generally just use it as a backup system. If it&#x27;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.<p>I&#x27;m not sure there&#x27;s a generalizable pattern there for which has a lower actual time interval between commit&#x2F;pushes but I suspect that I tend to be spammier with them in personal projects.
TheOtherHobbesabout 9 years ago
Incrementally, every time I make a small but significant change. I treat it like a super-save, so I can get that latest slice of work back if the disk on my dev machine dies. (The dev machine is currently a Linode.)<p>30 seconds is too often. Once a day isn&#x27;t often enough.
masukomiabout 9 years ago
&gt; I&#x27;ll commit for small, incremental changes. Each commit is a semantic change to me- could be a small change applied in the same way across multiple files, or a larger change in a single file that does one thing. - jtfairbank<p>I agree with that but i&#x27;d add that i&#x27;ll also commit at any stopping point. Need to leave for work? Commit. Need to go home ? commit. Doesn&#x27;t matter how broken the code is at that point. I&#x27;ll rebase the ugly commit away. Usually the ugly commit will have a message like &quot;INTERIM COMMIT - REBASE ME&quot;<p>I&#x27;ll also happily push these ugly commits to a topic branch on a remote machine for backup purposes as long as I know that no-one else is working on that branch.
Raed667about 9 years ago
I commit when I add a feature, fix a bug, anything that &quot;feels&quot; like an incremental step. I try to commit as much as possible so I can revert without losing much work.<p>I push whenever I&#x27;m about to shutdown the laptop or by the end of they day.
tokenroveabout 9 years ago
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&#x27;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.<p>I prefer this over trying to get every commit right the first time. I also feel there&#x27;s a nice change of pace in the process of stepping back, looking over the previous work, and shaping it into something that communicates the ideas well to reviewers.
评论 #11224346 未加载
tedmistonabout 9 years ago
I find it varies with the work being done vs. relating to a discrete time duration.<p>In general, I try to be very atomic. As an added benefit, this makes it simpler for someone doing a git bisect later.<p>Fixing minor typos or copy changes across a few files could result in several commits within 15 minutes.<p>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.
mycroft-holmesabout 9 years ago
Let&#x27;s be honest, that consultant has never pushed a line of code in their life.<p>You&#x27;re probably committing and pushing at acceptable times. Screw the consultant.
MalcolmDiggsabout 9 years ago
I use Scrum and I usually commit about once an hour. More if I&#x27;m just bug-fixing or correcting typos or adding comments.<p>Committing every 30 seconds seems like it would knock me out of my flow so often that I wouldn&#x27;t get anything done.<p>That being said, if I&#x27;m working in the same files as someone else, I&#x27;ll commit every few minutes (and so will they) so that the amount of conflicts we&#x27;re creating don&#x27;t get out of hand.
评论 #11223840 未加载
评论 #11223361 未加载
brianwawokabout 9 years ago
Once per feature or major change. Smallest would be a 1 liner that takes 10 seconds. Average maybe 1 hour. At the end of 1 day I commit and push to a private branch just in case my laptop bursts into flames overnight.
Grue3about 9 years ago
Commit amend for small changes.<p>New commit for new logical &quot;part&quot; of feature.<p>Rebase interactive when feature is &quot;done&quot; (in some way) to fix commit messages and squash some extraneous commits.<p>Push (as a branch in forked repo).<p>Sometimes I push before the feature is complete for backup&#x2F;accountability purposes, but then I rebase anyway and push force the thing once it&#x27;s done.
doqueabout 9 years ago
I commit everything that I want to be able to recover&#x2F;share. If it&#x27;s necessary to share (e.g. open a pull request), or if I want to have a distributed backup of my work, I&#x27;ll push.
quintesabout 9 years ago
check in when it makes sense. In a feature branch? whenever you like as long as it&#x27;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.<p>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.
Ditiabout 9 years ago
I commit <i>all the time</i>, even for minor changes and uncompilable code. But I do this on a WIP branch, which I rebase onto my main branch at the end of the day.
Redoubtsabout 9 years ago
To my private branch? As often as I feel I need to feel safe about backing up the changes I made.<p>How often do you press &quot;Save Game&quot; during a new level?
rabee3about 9 years ago
I commit my changes as little checkpoints of the progress of my work, once a feature or a bug is done locally, I push it for people to review.
rahulgr8888about 9 years ago
I definitely commit at the end of the day. you should have everything you did in a day on some backup other than your dev environment
masters3dabout 9 years ago
Scrum is not about the how, as long as your are getting your stories done. Something seems off.
CiPHPerCoderabout 9 years ago
Approximately once or twice per hour.