git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Feature request: prevent push -f from pushing all branches at once
@ 2013-07-03 23:30 Dany
  2013-07-03 23:38 ` Jonathan Nieder
  2013-07-04  8:06 ` Matthieu Moy
  0 siblings, 2 replies; 3+ messages in thread
From: Dany @ 2013-07-03 23:30 UTC (permalink / raw
  To: git

Hi,

I 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.

I'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.)

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?

Would love any thoughts or suggestions on this.

Thanks,
--Dany.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Feature request: prevent push -f from pushing all branches at once
  2013-07-03 23:30 Feature request: prevent push -f from pushing all branches at once Dany
@ 2013-07-03 23:38 ` Jonathan Nieder
  2013-07-04  8:06 ` Matthieu Moy
  1 sibling, 0 replies; 3+ messages in thread
From: Jonathan Nieder @ 2013-07-03 23:38 UTC (permalink / raw
  To: Dany; +Cc: git

Hi Dany,

Dany wrote:

> I 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.

Yeah, I agree that this is lousy.

When you run "git push" or "git push -f" without further arguments,
current versions of git print a long message:

| $ git push
| warning: push.default is unset; its implicit value is changing in
| Git 2.0 from 'matching' to 'simple'. To squelch this message
| and maintain the current behavior after the default changes, use:
| 
|   git config --global push.default matching
| 
| To squelch this message and adopt the new behavior now, use:
| 
|   git config --global push.default simple
| 
| See 'git help config' and search for 'push.default' for further information.
| (the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
| 'current' instead of 'simple' if you sometimes use older versions of Git)

This is intended as a warning that git is not necessarily going to
push the branches that you intended, with instructions for teaching
git what you actually meant.  For historical reasons (to support
habits and scripts) the current default is the "push matching
branches" behavior you ran into, but in the future the default will be
a more conservative "push the current branch, and only if it is
configured to pull from the matching branch", allowing this long
message to go away.

What version of git are you using?  Any ideas about how that message
could be improved?  (Perhaps it is too long to work as an effective
warning.)

Thanks and hope that helps,
Jonathan

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Feature request: prevent push -f from pushing all branches at once
  2013-07-03 23:30 Feature request: prevent push -f from pushing all branches at once Dany
  2013-07-03 23:38 ` Jonathan Nieder
@ 2013-07-04  8:06 ` Matthieu Moy
  1 sibling, 0 replies; 3+ messages in thread
From: Matthieu Moy @ 2013-07-04  8:06 UTC (permalink / raw
  To: Dany; +Cc: git

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/

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-07-04  8:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-03 23:30 Feature request: prevent push -f from pushing all branches at once Dany
2013-07-03 23:38 ` Jonathan Nieder
2013-07-04  8:06 ` Matthieu Moy

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).