HACKER Q&A
📣 bjourne

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?


  👤 outsomnia Accepted Answer ✓
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.


👤 waste_monk
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.


👤 Faaak
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


👤 tummybug
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.

👤 Jtsummers
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.


👤 blumomo
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.

👤 bronzecarnage
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


👤 iex_xei
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...


👤 mritzmann
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.

👤 willcipriano
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.


👤 Nales
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

👤 aneil
Put a sign on your inner front door: "Did you commit your changes?"

👤 captainbland
Commit small, commit often. The smaller the commits, the less you'll lose when you do forget.

👤 heavenlyblue
The solution is simple: commit and push code all the time.

👤 dustymcp
i work only on one machine, my laptops are basically just terminals at this point ssh into my workmachine.

👤 epirogov
I cured it with vitamin B6 B12 :D