Re: Feature request: prevent push -f from pushing all branches at once
Dany <nessup@gmail.com> writes:
> Again, 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?
I don't think the case of "force push" is very different from the "non-force push". If you're surprised that "git push -f" pushes everything, most likely you didn't want a plain "git push" to push everything either.
There are already several measures against this. The first is mentionned in Jonathan's message: Git 2.0 will only push one branch by default (-f or not). You can already get this behavior by setting push.default (if your Git version is too old, set it to "current" for example, read "git config --help").
Another measure is a better documentation. We've just merged the change below. In short: don't run "git push -f", but run e.g. "git push origin +master".
commit 70495b556f5685afe0e41988e42d48b2331d77a0
Author: Matthieu Moy <Matthieu.Moy@imag.fr>
Date: Mon Jun 17 19:52:41 2013 +0200
Documentation/git-push.txt: explain better cases where --force is dangerous
The behavior of "git push --force" is rather clear when it updates only
one remote ref, but running it when pushing several branches can really
be dangerous. Warn the users a bit more and give them the alternative to
push only one branch.
Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>diff --git a/Documentation/git-push.txt b/Documentation/git-push.txt
index 8b637d3..28a17c3 100644
--- a/Documentation/git-push.txt
+++ b/Documentation/git-push.txt
@@ -124,6 +124,15 @@ no `push.default` configuration variable is set.
not an ancestor of the local ref used to overwrite it.
This flag disables the check. This can cause the
remote repository to lose commits; use it with care.
+ Note that `--force` applies to all the refs that are pushed,
+ hence using it with `push.default` set to `matching` or with
+ multiple push destinations configured with `remote.*.push`
+ may overwrite refs other than the current branch (including
+ local refs that are strictly behind their remote counterpart).
+ To force a push to only one branch, use a `+` in front of the
+ refspec to push (e.g `git push origin +master` to force a push
+ to the `master` branch). See the `<refspec>...` section above
+ for details.
--repo=<repository>::
This option is only relevant if no <repository> argument is
--
Matthieu Moy
http://www-verimag.imag.fr/~moy/