git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Question: is there a possibility of getting a warning before a git push -f

From
Aditya Garg <gargaditya08@live.com>
Date
Jun 12, 2025, 11:49 UTC
Message-ID
<PN3PR01MB959737A5CCD375854E0E9385B874A@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM>
In-Reply-To
<CALnO6CA-SvasocZ_tbN2_-DiGCO55W6gyXDjJZqRo5Y3D4JRmg@mail.gmail.com>
On 12/06/25 4:48 am, D. Ben Knoble wrote:
Show 20 quoted lines
>> Le 9 juin 2025 à 12:47, Aditya Garg <gargaditya08@live.com> a écrit :
>>
>> One thing I sometimes encounter is that I sometimes git push -f and moments later I realise I did it at the wrong time, result being a disaster.
> 
> 2 effective habits I like:
> - Check what I’m pushing first.
> - Only force when absolutely needed, and even then default to a
> “strict” version (force-with-lease *and* force-if-includes; I use an
> alias “pf” and some config to make it easy, since I do force-push
> regularly in a rebase-heavy workflow).
> 
> Expanding a bit:
> 
> I have a “git-div” script that will show me the graph in the way I
> like between HEAD and @{push}, or @{upstream} if those are the same
> revision [it accepts arbitrary revisions though]. It was mostly
> inspired by mjd’s git-vee, and uses lots of annotations (cherry-mark,
> left-right, boundary) to give a quick HUD.
> 
> https://github.com/benknoble/Dotfiles/blob/master/links/bin/git-div
Ah nice, I was searching for something similar.
Show 20 quoted lines
> 
> (“graph” is an alias for git-log with the graph and oneline options)
> 
> I also use(d to) use show-branch a lot, and I have aliases sbu =
> show-branch HEAD @{upstream} and sbup = sbu @{push} that I still use
> sometimes.
> 
> As I recently told some colleagues, I consider regularly reviewing
> where in the commit graph I am equally as important as checking
> git-status.
> 
> The second bullet is probably self-explanatory, but the basic idea is
> to give myself the most protection I can, and only weaken it as
> necessary. In fact, I almost never need to remove any of those
> “strict” flags to force-push except when I’m intentionally
> force-pushing from a detached HEAD
> (https://lore.kernel.org/git/CALnO6CCk0SgwObQRnpd5Pt_DvCKF8dBmyVHivU6Nr_O-GusGLA@mail.gmail.com/).
> 
> 
>> I was wondering if a little [y/N] warning could be possible before the risky command gets executed. I saw the code for push superficially and I don't think it's implemented. I think it would be a nice feature though.
Previous: D. Ben Knoble
Message 5 of 5 in “Question: is there a possibility of getting a warning before a git push -f”
  1. Aditya GargJun 9, 2025
  2. Junio C HamanoJun 9, 2025
  3. Aditya GargJun 9, 2025
  4. D. Ben KnobleJun 11, 2025
  5. Aditya GargJun 12, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.