How often do you guys commmit / push ? I push in my changes when I have completely finished working on a feature / module
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 "in progress" 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 / time down.
If you just updated a typo in some comments, it could make sense to commit it and it could take 30 seconds.
Now if you are always committing as frequently, either you are working on very easy tasks with no dependencies, either there is an issue.
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"
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.
Just curious -- do you squash commits when merging one of these feature branches?
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.
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.
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 "main" 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.
Every 30 seconds seems like a bit much, but it wouldn't be unreasonable to say I commit and push 10x a day.
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.
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.
30 seconds is too often. Once a day isn't often enough.
I agree with that but i'd add that i'll also commit at any stopping point. Need to leave for work? Commit. Need to go home ? commit. Doesn't matter how broken the code is at that point. I'll rebase the ugly commit away. Usually the ugly commit will have a message like "INTERIM COMMIT - REBASE ME"
I'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.
I push whenever I'm about to shutdown the laptop or by the end of they day.
I prefer this over trying to get every commit right the first time. I also feel there'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.
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.
You're probably committing and pushing at acceptable times. Screw the consultant.
Committing every 30 seconds seems like it would knock me out of my flow so often that I wouldn't get anything done.
That being said, if I'm working in the same files as someone else, I'll commit every few minutes (and so will they) so that the amount of conflicts we're creating don't get out of hand.
New commit for new logical "part" of feature.
Rebase interactive when feature is "done" (in some way) to fix commit messages and squash some extraneous commits.
Push (as a branch in forked repo).
Sometimes I push before the feature is complete for backup/accountability purposes, but then I rebase anyway and push force the thing once it's done.
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.
How often do you press "Save Game" during a new level?