The title of this post is a rhetorical question. At least I think it is. Or I like to think it is. What I can say with certainty is that I forgot my fair share of pushes. 😅
Sometimes I was the one tripping over my own mistake (Why is that commit not live? Ah, because the pipeline did not run. Because I did not push. facepalm). Sometimes my colleagues had to find out.☺️
So I thought it should not be that hard to get some automation in place to avoid these shenanigans. And sure enough it is. This is how it looks:
The bulk of the work is done by this little project aptly named git-remind. It is pretty simple to setup. Beyond putting the executable on your PATH you have to tell it which repositories you want reminders for in your git config:
git config --global remind.paths '/path/to/your/projects/*,/and/some/other/repo'
git-remind status tells you about pushes and potential commits that
are missing. My interest is in missing pushes only, so I adapted the suggested
jump script accordingly:
alias grj='cd $(git-remind status | grep " push:" | sed "s/.* push: //" | fzf)'
Now we can jump directly to the repositories in question. But what about reminders? Sadly I could not get the builtin notification functionality working via cron. So I wrote this tiny script:
#!/usr/bin/env bash set -euo pipefail UNPUSHED_COMMITS=$(git remind status | grep " push:" | wc -l) if [ "$UNPUSHED_COMMITS" != "0" ]; then notify-send --expire-time=60000 "Unpushed commits:" "There are $UNPUSHED_COMMITS unpushed commits. Run grj to find them." fi
It is called via cron every minute1:
* * * * * XDG_RUNTIME_DIR=/run/user/$(id -u) chronic $HOME/scripts/notify_on_forgotten_push.sh
I found two cases in which unpushed commits do not trigger an alert by git-remind:
If there is no remote branch setup
If the branch is currently not checked out
As I usually do trunk based development this does not bother me. But if you need this you should probably replace git-remind with something else.
1Cautious reminder: For that to work you have to set
PATH variable in crontab accordingly if you have not already.