git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Erik Cervin Edin <erik@cervined.in>
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: Tue, 25 Oct 2022 09:56:15 +0200	[thread overview]
Message-ID: <CA+JQ7M_woJmQdaB24-eNxSRJLN4GPgTyZcPfKsXAkP+B1QOT-Q@mail.gmail.com> (raw)
In-Reply-To: <491oWe6HDMJXQK2Ru2VbzFrlUajNlVhnIErZZ1dxUaPpCElsgpASAEQFc2Zi1R4G53hAIMHopETEJn7E_TzeeC6uOzGBffQDRK2AWYPIxKQ=@protonmail.com>

On Sat, Oct 22, 2022 at 7:02 PM Sergey <sryze@protonmail.com> wrote:
>
> 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 because it would promote usage of this feature among the users. I just wanted to know your opinions and see if someone else would find it useul or it's just a dumb idea.

Once you know the relevant options, it's pretty trivial to roll your
own script/workflow/configuration that suits your own work case. I'll
share how I solve the problem you describe. First, I'd like to mention
  git pull --rebase
which is basically
  git fetch origin && git rebase @{upstream}
or
  git pull --rebase=merges
which is basically
  git fetch origin && git rebase --rebase-merges @{upstream}
This does a fetch and afterwards, attempts to rebase any local changes
on top of the remote tracking branch. I'd recommend this approach over
force pushing. It keeps forced history rewrites away from the upstream
repository, which is generally best reserved for "truer" or more
finished work. It also allows for better recovery, in case you mess
up, chances are your history is preserved in the reflog. This can be
configured as the default either globally, per repo or per branch
https://git-scm.com/docs/git-config#Documentation/git-config.txt-pullrebase

Be aware that there are potential situations where this will not
automagically resolve the difference in history in a way that you may
expect and I'd only configure this as default if you feel comfortable
rolling back in case that situation arises. As a starting point, you
can manually initialize the rebase using @{upstream} or @{U}
 git fetch
 git rebase @{U}

If you want to investigate the divergence between a local branch and
its upstream, there are several commands that may be useful depending
on exactly how you want to compare them (often situational in my
experience.) The see which is newer you can run
  git show -q --format=fuller HEAD HEAD@{U}
but sometimes you want to know more say, how do the trees differ
  git log --online --graph HEAD...HEAD@{U}
or perhaps the difference in contents
  git diff HEAD HEAD@{U}
etc. etc.

Happy hunting!

      parent reply	other threads:[~2022-10-25  7:57 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
2022-10-25  7:56 ` Erik Cervin Edin [this message]

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=CA+JQ7M_woJmQdaB24-eNxSRJLN4GPgTyZcPfKsXAkP+B1QOT-Q@mail.gmail.com \
    --to=erik@cervined.in \
    --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).