News for hackers. Stuff that matters.

Ask HN: How do you stop forgetting to commit or push?

This happens to me frequently. I hack on a project at my laptop or home computer. The next day I travel to my office only to realize that I didn't commit or push any of yesterday's work. Thus to continue working on whatever I was working on I need to go home, push my changes, and then return to office. Very frustrating.

Does this happen to anyone else? How do you prevent it?

( 18 comments | 10 points | on HN )
Re:Ask HN: How do you stop forgetting to commit or push? by outsomnia on Monday March 28, 2022 @06:21AM (#30829021)
It's not a good idea to mix work done on employer devices with work done on your home devices, for the employer there's a security problem and for the employee a bad employer may lay claim to everything you do on your home computer.

So you should solve this by only working on work stuff using work devices, or, eg, ssh into your work box to do stuff from home.

Re:Ask HN: How do you stop forgetting to commit or push? by waste_monk on Monday March 28, 2022 @08:23AM (#30829711)
If a problem bites you on the ass enough times, you'll either correct it yourself or run out of ass.

That is, it sounds like you've only suffered mild inconvenience so far, not any real consequence (failure to meet deadline, being reprimanded by boss for not making progress, etc.). Once that happens, it is a powerful motivator not to make the same mistake again.

Re:Ask HN: How do you stop forgetting to commit or push? by Faaak on Monday March 28, 2022 @07:22AM (#30829317)
Customise your shell (bash, zsh, etc.) in order to show on each prompt the status of your git repo (untracked changes, commits not on a remote, etc..). When I see some red, I now something is amiss and it really helps.

Also, `tig` is a great tool to explore the git history

Re:Ask HN: How do you stop forgetting to commit or push? by noir_lord on Monday March 28, 2022 @07:59AM (#30829539)
I just install zsh/oh-my-zsh and it has all that nicely setup out the box.

I love oh-my-zsh and it's plugins.

Re:Ask HN: How do you stop forgetting to commit or push? by tummybug on Monday March 28, 2022 @07:42AM (#30829426)
I have a portforward on my home router and simply ssh in to my always on desktop. This is also useful for not having to keep sensitive documents on a device I may lose while out and about.
Re:Ask HN: How do you stop forgetting to commit or push? by Jtsummers on Monday March 28, 2022 @11:13AM (#30831341)
Same way I learned to use C-s (or whatever your editor's equivalent is) as a habit gesture. I got burned. "Save early, save often" was extended, for me, with "commit early, commit often", also after getting burned with an over-large (and broken in a few ways) commit that had merge conflicts with other people's work.

Pushing is the same, except it's an extension of my "make a backup of the hard drive because it can fail at any time" learning experience. I push because that's how the backup works for a git repo (also collaboration), I backup because I got burned when a HDD failed catastrophically and I had no consistent backups.

Something fails, learn from the experience and make new habits or processes (automated or manual) to avoid those failures in the future.

Re:Ask HN: How do you stop forgetting to commit or push? by blumomo on Monday March 28, 2022 @07:52AM (#30829496)
Are you making many small commits every some minutes? Or are you usually waiting til the end of the day to create one big commit? If you make it a habit to commit often and in small steps, `git commit` will become an automatic response like pressing Ctrl+S in the 90s and early 2000s.
Re:Ask HN: How do you stop forgetting to commit or push? by selbyk on Monday March 28, 2022 @10:15AM (#30830703)
Doesn't matter how often you commit if you forget to push
Re:Ask HN: How do you stop forgetting to commit or push? by bronzecarnage on Monday March 28, 2022 @09:53AM (#30830476)
It's about creating a habit, like many people mentioned here. For me, the git commandline process was a bit too much hassle and typing to do if I wanted to do it atomically. In the end, I wound up using lazygit[0] and the nvim plugin[1] to make life easier. It makes committing only selected chunks a lot easier, not to mention easier cherry picking and other stuff.

[0]: https://github.com/jesseduffield/lazygit [1]: https://github.com/kdheepak/lazygit.nvim

Re:Ask HN: How do you stop forgetting to commit or push? by iex_xei on Monday March 28, 2022 @09:02AM (#30830090)
These days I'm using a script[0]. It checks all directories under ˋ$HOME/github.com/ˋ for changes and opens lazygit if there are changes. You can replace that line with a ˋgit commit -am "wip" ; git push origin/my-current-branchˋ for an ultimate lazy solution, to rebase later. :)

[0]: https://gist.github.com/iesahin/398af2556f5ae809c4b368ffc2ef...

Re:Ask HN: How do you stop forgetting to commit or push? by mritzmann on Monday March 28, 2022 @07:58AM (#30829531)
Use the same device. With a powerful notebook and a docking station (usb c to power, hdmi, mous, keyboard) this is very comfortable. At least for me.
Re:Ask HN: How do you stop forgetting to commit or push? by willcipriano on Monday March 28, 2022 @08:03AM (#30829566)
I use squashing on my PRs so I dont annoy others and then do it at each logical step.

First commit - Function to do task Completed

Second commit - Added unit test

Third commit - Linter fixes

Forth commit - Fix bug

And so on.

Re:Ask HN: How do you stop forgetting to commit or push? by Nales on Monday March 28, 2022 @10:51AM (#30831064)
I wrote a bunch of scripts, on Linux, to show me repositories with uncommitted changes when I open a terminal. Here is my blog post about them: https://www.nales.xyz/en/blog/follow-changes-repos.html
Re:Ask HN: How do you stop forgetting to commit or push? by aneil on Monday March 28, 2022 @08:49AM (#30829969)
Put a sign on your inner front door: "Did you commit your changes?"
Re:Ask HN: How do you stop forgetting to commit or push? by captainbland on Monday March 28, 2022 @08:51AM (#30829993)
Commit small, commit often. The smaller the commits, the less you'll lose when you do forget.
Re:Ask HN: How do you stop forgetting to commit or push? by heavenlyblue on Monday March 28, 2022 @10:33AM (#30830894)
The solution is simple: commit and push code all the time.
Re:Ask HN: How do you stop forgetting to commit or push? by dustymcp on Monday March 28, 2022 @10:01AM (#30830550)
i work only on one machine, my laptops are basically just terminals at this point ssh into my workmachine.
Re:Ask HN: How do you stop forgetting to commit or push? by epirogov on Monday March 28, 2022 @01:30PM (#30833112)
I cured it with vitamin B6 B12 :D