{"thread":{"id":"34340","subject":"Feature request: prevent push -f from pushing all branches at once","startedAt":"2013-07-03T23:30:27Z","lastAt":"2013-07-04T08:06:59Z","messageCount":3,"participants":["Dany","Jonathan Nieder","Matthieu Moy"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"222518","messageId":"ADE9FE42-FC10-4976-8E6A-290B101DD17A@gmail.com","threadId":"34340","inReplyTo":null,"subject":"Feature request: prevent push -f from pushing all branches at once","fromName":"Dany","fromEmail":"nessup@gmail.com","sentAt":"2013-07-03T23:30:27Z","receivedAt":"2013-07-03T23:30:27Z","isPatch":false,"sender":{"key":"nessup@gmail.com","avatar":null},"body":"Hi,\n\nI had a pretty sucky thing happen to me today: while remote tracking a non-master branch, I force pushed. This had the intended effect of force pushing the branch I was working on, but also the unintended function of force pushing all branches I wasn't on.\n\nI'm open to anyone's thoughts about this (or even a suggestion as to how to avoid this in the future), but as far as I know, in 99% of cases, a developer does not intend to force push all branches he is remote tracking on his system when he types `git push -f`. Now I know that that's what will happen, but I wonder why git does this (and, furthermore, why git doesn't prevent force pushing multiple branches at once.)\n\nAgain, I think the case where one intends to force push many branches is certainly not as common as the case where one intends to force push one branch, so why does git's default behavior leave the user in the position of fscking himself over pretty badly?\n\nWould love any thoughts or suggestions on this.\n\nThanks,\n--Dany.\n"},{"id":"222519","messageId":"20130703233804.GW408@google.com","threadId":"34340","inReplyTo":"ADE9FE42-FC10-4976-8E6A-290B101DD17A@gmail.com","subject":"Re: Feature request: prevent push -f from pushing all branches at once","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2013-07-03T23:38:04Z","receivedAt":"2013-07-03T23:38:04Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi Dany,\n\nDany wrote:\n\n> I had a pretty sucky thing happen to me today: while remote tracking\n> a non-master branch, I force pushed. This had the intended effect of\n> force pushing the branch I was working on, but also the unintended\n> function of force pushing all branches I wasn't on.\n\nYeah, I agree that this is lousy.\n\nWhen you run \"git push\" or \"git push -f\" without further arguments,\ncurrent versions of git print a long message:\n\n| $ git push\n| warning: push.default is unset; its implicit value is changing in\n| Git 2.0 from 'matching' to 'simple'. To squelch this message\n| and maintain the current behavior after the default changes, use:\n| \n|   git config --global push.default matching\n| \n| To squelch this message and adopt the new behavior now, use:\n| \n|   git config --global push.default simple\n| \n| See 'git help config' and search for 'push.default' for further information.\n| (the 'simple' mode was introduced in Git 1.7.11. Use the similar mode\n| 'current' instead of 'simple' if you sometimes use older versions of Git)\n\nThis is intended as a warning that git is not necessarily going to\npush the branches that you intended, with instructions for teaching\ngit what you actually meant.  For historical reasons (to support\nhabits and scripts) the current default is the \"push matching\nbranches\" behavior you ran into, but in the future the default will be\na more conservative \"push the current branch, and only if it is\nconfigured to pull from the matching branch\", allowing this long\nmessage to go away.\n\nWhat version of git are you using?  Any ideas about how that message\ncould be improved?  (Perhaps it is too long to work as an effective\nwarning.)\n\nThanks and hope that helps,\nJonathan\n"},{"id":"222530","messageId":"vpq7gh67nq4.fsf@anie.imag.fr","threadId":"34340","inReplyTo":"ADE9FE42-FC10-4976-8E6A-290B101DD17A@gmail.com","subject":"Re: Feature request: prevent push -f from pushing all branches at once","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2013-07-04T08:06:59Z","receivedAt":"2013-07-04T08:06:59Z","isPatch":false,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Dany <nessup@gmail.com> writes:\n\n> Again, I think the case where one intends to force push many branches\n> is certainly not as common as the case where one intends to force push\n> one branch, so why does git's default behavior leave the user in the\n> position of fscking himself over pretty badly?\n\nI don't think the case of \"force push\" is very different from the\n\"non-force push\". If you're surprised that \"git push -f\" pushes\neverything, most likely you didn't want a plain \"git push\" to push\neverything either.\n\nThere are already several measures against this. The first is mentionned\nin Jonathan's message: Git 2.0 will only push one branch by default (-f\nor not). You can already get this behavior by setting push.default (if\nyour Git version is too old, set it to \"current\" for example, read \"git\nconfig --help\").\n\nAnother measure is a better documentation. We've just merged the change\nbelow. In short: don't run \"git push -f\", but run e.g. \"git push origin\n+master\".\n\ncommit 70495b556f5685afe0e41988e42d48b2331d77a0\nAuthor: Matthieu Moy <Matthieu.Moy@imag.fr>\nDate:   Mon Jun 17 19:52:41 2013 +0200\n\n    Documentation/git-push.txt: explain better cases where --force is dangerous\n    \n    The behavior of \"git push --force\" is rather clear when it updates only\n    one remote ref, but running it when pushing several branches can really\n    be dangerous. Warn the users a bit more and give them the alternative to\n    push only one branch.\n    \n    Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>\n    Signed-off-by: Junio C Hamano <gitster@pobox.com>\n\ndiff --git a/Documentation/git-push.txt b/Documentation/git-push.txt\nindex 8b637d3..28a17c3 100644\n--- a/Documentation/git-push.txt\n+++ b/Documentation/git-push.txt\n@@ -124,6 +124,15 @@ no `push.default` configuration variable is set.\n        not an ancestor of the local ref used to overwrite it.\n        This flag disables the check.  This can cause the\n        remote repository to lose commits; use it with care.\n+       Note that `--force` applies to all the refs that are pushed,\n+       hence using it with `push.default` set to `matching` or with\n+       multiple push destinations configured with `remote.*.push`\n+       may overwrite refs other than the current branch (including\n+       local refs that are strictly behind their remote counterpart).\n+       To force a push to only one branch, use a `+` in front of the\n+       refspec to push (e.g `git push origin +master` to force a push\n+       to the `master` branch). See the `<refspec>...` section above\n+       for details.\n \n --repo=<repository>::\n        This option is only relevant if no <repository> argument is\n\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"}]}