How many times did I push at 2am so I could go home, get to the freeway entrance, realized I fucked something up, sighed, and turned around to go back and fix it...
(This was like 1999, we didn't have access to Perforce from home).
After a year or so I realized I should just develop the willpower to check it in after sleeping on it.
"No, wait, it's not what you think! There's a continuous integration system, a commit would've triggered a new build! It might have paged the oncall! Babe! The test suite has been flaky lately!"
That's actually not that rare when I work later than usual. Some stupid problem my brain is too fried to solve. Eventually I give up, feeling defeat for the whole evening and solve the problem in 10 mins the next morning. Get enough sleep, people.
However, much research shows the hand banging against the wall period is required for you to achieve the morning breakthrough.
The sleeping break is where your neurons form new connections based their activity yesterday. The “thinking hard” and the frustration is a required part of the morning epiphany.
You should be pushing feature branches as you work on them, so if you have a crash or something, your work isn't lost. Builds should be triggered from pull requests on the main branch, if triggered by anything. You should never push directly to main. At least that's my preference.
Our ci/cd pipelines build also feature branches. I do push often, clean code. I don't push when I am tired enough that I can't trust my judgment that the code I am pushing is over my personal quality threshold. I add meaningful, concise commit messages. These are my rules.
I would lose max 3 hrs of work that I already know how to re do. I can live with that. I don't want to publish too much unfinished/unpolished work. There is always the chance someone might need the branch.
Even if drafts under development, I like to publish something that reaches the standard of my "best" me, not my "Friday evening" me
Honey, I was reviewing the new interns pull request. She was having a real hard time. We kept pushing and pulling until we eventually found ourselves getting that commit all over the codebase. Needless to say it won't happen again, it was a one night standing review.