Ask HN: How do you stop forgetting to commit or push?
19 comments
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.
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.
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
[0]: https://github.com/jesseduffield/lazygit [1]: https://github.com/kdheepak/lazygit.nvim
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...
[0]: https://gist.github.com/iesahin/398af2556f5ae809c4b368ffc2ef...
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
Put a sign on your inner front door: "Did you commit your changes?"
Commit small, commit often. The smaller the commits, the less you'll lose when you do forget.
The solution is simple: commit and push code all the time.
i work only on one machine, my laptops are basically just terminals at this point ssh into my workmachine.
[deleted]
I cured it with vitamin B6 B12 :D
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.
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.
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
Also, `tig` is a great tool to explore the git history
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.
I love oh-my-zsh and it's plugins.
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.
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.
Doesn't matter how often you commit if you forget to push
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.
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.
First commit - Function to do task Completed
Second commit - Added unit test
Third commit - Linter fixes
Forth commit - Fix bug
And so on.
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.
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.
Does this happen to anyone else? How do you prevent it?