git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Sergey <sryze@protonmail.com>
Cc: "git@vger.kernel.org" <git@vger.kernel.org>
Subject: Re: Adding --force-if-newer flag to git push
Date: Sat, 22 Oct 2022 10:48:33 -0700	[thread overview]
Message-ID: <xmqqmt9nhhqm.fsf@gitster.g> (raw)
In-Reply-To: <491oWe6HDMJXQK2Ru2VbzFrlUajNlVhnIErZZ1dxUaPpCElsgpASAEQFc2Zi1R4G53hAIMHopETEJn7E_TzeeC6uOzGBffQDRK2AWYPIxKQ=@protonmail.com> (Sergey's message of "Sat, 22 Oct 2022 16:58:55 +0000")

Sergey <sryze@protonmail.com> writes:

> Would it be a good idea to add a new flag --force-if-newer to the
> "git push" command, so that force-pushing would succeed only if
> the last local commit's date is newer than that on the remote
> branch?

Probably not.  I do not see how we can force the clock on the
machine that created the commit (which may not be even yours)
sitting at the tip on the branch you are trying to overwrite to be
in sync with the clock on the local machine on which you created the
commit you are trying to use to replace it with.

> Sometimes I find that a feature like this would be useful when I
> work on multiple different computers and I want to just push all
> local branches to the repo at once to sync it with whatever is the
> latest version. I know that using --force is kind of frowned upon
> in the Git community, so this is probably not the best idea ...

In such a workflow, not forcing is the more reasonable option.

After seeing your push fail because you forgot that you have pushed
other changes from another machine, you first fetch and consolidate
what was done on the local machine into what you have pushed before
to the remote, and push again.  If you rebased your local work on
top of what you pushed there but forgot that you have pushed, this
time around the push will fast-forward.  If you merged your local
work, it will also fast-forward.  Either way, not forcing would have
caught you from losing some work you did on another machine, and
pushing the result can be done without forcing.


  reply	other threads:[~2022-10-22 17:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-22 16:58 Adding --force-if-newer flag to git push Sergey
2022-10-22 17:48 ` Junio C Hamano [this message]
2022-10-25  7:56 ` Erik Cervin Edin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqmt9nhhqm.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=sryze@protonmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).