{"thread":{"id":"63609","subject":"Question: is there a possibility of getting a warning before a git push -f","startedAt":"2025-06-09T16:46:59Z","lastAt":"2025-06-12T11:49:52Z","messageCount":5,"participants":["Aditya Garg","Junio C Hamano","D. Ben Knoble"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"519983","messageId":"PN0PR01MB95880EAA98466C9AB049BA44B86BA@PN0PR01MB9588.INDPRD01.PROD.OUTLOOK.COM","threadId":"63609","inReplyTo":null,"subject":"Question: is there a possibility of getting a warning before a git push -f","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-06-09T16:46:52Z","receivedAt":"2025-06-09T16:46:59Z","isPatch":false,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"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. 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.\n"},{"id":"519990","messageId":"xmqqldq0rc3b.fsf@gitster.g","threadId":"63609","inReplyTo":"PN0PR01MB95880EAA98466C9AB049BA44B86BA@PN0PR01MB9588.INDPRD01.PROD.OUTLOOK.COM","subject":"Re: Question: is there a possibility of getting a warning before a git push -f","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-06-09T18:42:16Z","receivedAt":"2025-06-09T18:42:19Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Aditya Garg <gargaditya08@live.com> writes:\n\n> One thing I sometimes encounter is that I sometimes git push -f and\n> moments later I realise I did it at the wrong time, result being a\n> disaster. I was wondering if a little [y/N] warning could be possible\n> before the risky command gets executed. I saw the code for push\n> superficially and I don't think it's implemented. I think it would be\n> a nice feature though.\n\nI suspect that an even nicer feature that is more generally\napplicable is a patch to your shell to make any command you give it\nis not run for a few seconds to give you a chance to kill it with\n^C.  You do not want to run around castrating a bunch of commands\nand features like \"git push\", \"rm\", \">overwrite-with-redirect\", and\nall the other \"destructive\" things you may regret doing.  There are\nliterally too many.\n\nQuite honestly, \"-f\" or \"--force\" should be a hint enough that the\nuser wants the command to do what the command usually does not allow\nthem to do to avoid potentially dangerous operations.\n\nI would expect that many people will truly get annoyed when \"git\nanycommand --force\" starts asking \"That's very dangerous---are you\nsure?\" for confirmations, and would complain \"Yes, otherwise I\nwouldn't be giving you '--force'---just do it as I told you\".\n"},{"id":"519993","messageId":"PN3PR01MB9597D5059F9C9E0FCF442CB0B86BA@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","threadId":"63609","inReplyTo":"xmqqldq0rc3b.fsf@gitster.g","subject":"Re: Question: is there a possibility of getting a warning before a git push -f","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-06-09T18:44:04Z","receivedAt":"2025-06-09T18:44:07Z","isPatch":false,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"\n\n> On 10 Jun 2025, at 12:12 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> \n> ﻿Aditya Garg <gargaditya08@live.com> writes:\n> \n>> One thing I sometimes encounter is that I sometimes git push -f and\n>> moments later I realise I did it at the wrong time, result being a\n>> disaster. I was wondering if a little [y/N] warning could be possible\n>> before the risky command gets executed. I saw the code for push\n>> superficially and I don't think it's implemented. I think it would be\n>> a nice feature though.\n> \n> I suspect that an even nicer feature that is more generally\n> applicable is a patch to your shell to make any command you give it\n> is not run for a few seconds to give you a chance to kill it with\n> ^C.  You do not want to run around castrating a bunch of commands\n> and features like \"git push\", \"rm\", \">overwrite-with-redirect\", and\n> all the other \"destructive\" things you may regret doing.  There are\n> literally too many.\n> \n> Quite honestly, \"-f\" or \"--force\" should be a hint enough that the\n> user wants the command to do what the command usually does not allow\n> them to do to avoid potentially dangerous operations.\n> \n> I would expect that many people will truly get annoyed when \"git\n> anycommand --force\" starts asking \"That's very dangerous---are you\n> sure?\" for confirmations, and would complain \"Yes, otherwise I\n> wouldn't be giving you '--force'---just do it as I told you\".\n\nFair"},{"id":"520133","messageId":"CALnO6CA-SvasocZ_tbN2_-DiGCO55W6gyXDjJZqRo5Y3D4JRmg@mail.gmail.com","threadId":"63609","inReplyTo":"PN0PR01MB95880EAA98466C9AB049BA44B86BA@PN0PR01MB9588.INDPRD01.PROD.OUTLOOK.COM","subject":"Re: Question: is there a possibility of getting a warning before a git push -f","fromName":"D. Ben Knoble","fromEmail":"ben.knoble@gmail.com","sentAt":"2025-06-11T23:18:14Z","receivedAt":"2025-06-11T23:18:27Z","isPatch":false,"sender":{"key":"ben.knoble@gmail.com","avatar":"https://avatars.githubusercontent.com/u/22802209?v=4"},"body":"> Le 9 juin 2025 à 12:47, Aditya Garg <gargaditya08@live.com> a écrit :\n>\n> ﻿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.\n\n2 effective habits I like:\n- Check what I’m pushing first.\n- Only force when absolutely needed, and even then default to a\n“strict” version (force-with-lease *and* force-if-includes; I use an\nalias “pf” and some config to make it easy, since I do force-push\nregularly in a rebase-heavy workflow).\n\nExpanding a bit:\n\nI have a “git-div” script that will show me the graph in the way I\nlike between HEAD and @{push}, or @{upstream} if those are the same\nrevision [it accepts arbitrary revisions though]. It was mostly\ninspired by mjd’s git-vee, and uses lots of annotations (cherry-mark,\nleft-right, boundary) to give a quick HUD.\n\nhttps://github.com/benknoble/Dotfiles/blob/master/links/bin/git-div\n\n(“graph” is an alias for git-log with the graph and oneline options)\n\nI also use(d to) use show-branch a lot, and I have aliases sbu =\nshow-branch HEAD @{upstream} and sbup = sbu @{push} that I still use\nsometimes.\n\nAs I recently told some colleagues, I consider regularly reviewing\nwhere in the commit graph I am equally as important as checking\ngit-status.\n\nThe second bullet is probably self-explanatory, but the basic idea is\nto give myself the most protection I can, and only weaken it as\nnecessary. In fact, I almost never need to remove any of those\n“strict” flags to force-push except when I’m intentionally\nforce-pushing from a detached HEAD\n(https://lore.kernel.org/git/CALnO6CCk0SgwObQRnpd5Pt_DvCKF8dBmyVHivU6Nr_O-GusGLA@mail.gmail.com/).\n\n\n> 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.\n"},{"id":"520168","messageId":"PN3PR01MB959737A5CCD375854E0E9385B874A@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM","threadId":"63609","inReplyTo":"CALnO6CA-SvasocZ_tbN2_-DiGCO55W6gyXDjJZqRo5Y3D4JRmg@mail.gmail.com","subject":"Re: Question: is there a possibility of getting a warning before a git push -f","fromName":"Aditya Garg","fromEmail":"gargaditya08@live.com","sentAt":"2025-06-12T11:49:38Z","receivedAt":"2025-06-12T11:49:52Z","isPatch":false,"sender":{"key":"gargaditya08@live.com","avatar":"https://avatars.githubusercontent.com/u/85610623?v=4"},"body":"\n\nOn 12/06/25 4:48 am, D. Ben Knoble wrote:\n>> Le 9 juin 2025 à 12:47, Aditya Garg <gargaditya08@live.com> a écrit :\n>>\n>> ﻿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.\n> \n> 2 effective habits I like:\n> - Check what I’m pushing first.\n> - Only force when absolutely needed, and even then default to a\n> “strict” version (force-with-lease *and* force-if-includes; I use an\n> alias “pf” and some config to make it easy, since I do force-push\n> regularly in a rebase-heavy workflow).\n> \n> Expanding a bit:\n> \n> I have a “git-div” script that will show me the graph in the way I\n> like between HEAD and @{push}, or @{upstream} if those are the same\n> revision [it accepts arbitrary revisions though]. It was mostly\n> inspired by mjd’s git-vee, and uses lots of annotations (cherry-mark,\n> left-right, boundary) to give a quick HUD.\n> \n> https://github.com/benknoble/Dotfiles/blob/master/links/bin/git-div\n\nAh nice, I was searching for something similar.\n> \n> (“graph” is an alias for git-log with the graph and oneline options)\n> \n> I also use(d to) use show-branch a lot, and I have aliases sbu =\n> show-branch HEAD @{upstream} and sbup = sbu @{push} that I still use\n> sometimes.\n> \n> As I recently told some colleagues, I consider regularly reviewing\n> where in the commit graph I am equally as important as checking\n> git-status.\n> \n> The second bullet is probably self-explanatory, but the basic idea is\n> to give myself the most protection I can, and only weaken it as\n> necessary. In fact, I almost never need to remove any of those\n> “strict” flags to force-push except when I’m intentionally\n> force-pushing from a detached HEAD\n> (https://lore.kernel.org/git/CALnO6CCk0SgwObQRnpd5Pt_DvCKF8dBmyVHivU6Nr_O-GusGLA@mail.gmail.com/).\n> \n> \n>> 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.\n\n"}]}