git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Guyot <tguyot@gmail.com>
To: Dan Stromberg <strombrg@gmail.com>, git@vger.kernel.org
Subject: Re: Weird merge records
Date: Sat, 6 May 2023 10:43:39 -0400	[thread overview]
Message-ID: <a611877f-c515-033c-e015-f3952b520c08@gmail.com> (raw)
In-Reply-To: <CAOvKW55oWs+atYyy-cTb=H0VhJx-V+M7_7FsqjdJ_jU9bR+8LA@mail.gmail.com>

Hi,

On 2023-04-28 11:34, Dan Stromberg wrote:
> I suspect the merge records may be coming from this small bit of shell
> script I've been using to pull from the master repo into my personal
> repo:
>      git fetch upstream
>      git checkout "$branch"
>      git config pull.rebase false
>      git pull upstream "$branch"
>      git push origin "$branch"
>
> Does that snippet look responsible? If yes, how might I change it to
> stop creating all those merge records? If no, any guesses what else
> might be causing it?

It is, indeed. This is IMHO something the developers should do 
themselves, in particular the pull may fail on conflicts and you don't 
seem to stop when it does.

First of all, that line:

git config pull.rebase false


You shouldn't change the user's config - you can instead use 
command-line switches with git-pull to force the desired behavior. In 
this case (which is also the default if there is no pull.rebase config) 
it will merge with the remote (and that merge will be a fast-forward if 
you have no added commits).

If you have local commits that aren't on the tip of the remote branch 
(i.e. someone else committed to the branch) you really have only two 
options here, merge or rebase (there is a new preserve option I think 
that I'm not familiar with, seems like rebase but preserving local 
merges). Rebase is the way to avoid merge commits, but conflicts can be 
painful to resolve if you have many commits to push.

Also note the first fetch is redundant, pull already does a fetch.

So you could change your script to:

     git checkout "$branch"
     git pull --rebase upstream "$branch" || exit 1
     git push origin "$branch"


In the case the pull fails, you will be left with conflicts to resolve - 
the instructions should be printed on screen and also shown in git-status.

Regards,

--
Thomas


  reply	other threads:[~2023-05-06 14:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-28 15:34 Weird merge records Dan Stromberg
2023-05-06 14:43 ` Thomas Guyot [this message]
2023-05-07 20:34   ` Felipe Contreras
2023-05-08 14:53     ` Dan Stromberg
2023-05-08 15:03       ` Felipe Contreras
2023-05-08 16:53         ` Dan Stromberg
2023-05-08 17:17           ` Felipe Contreras
2023-05-08 14:54   ` Dan Stromberg

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

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

  git send-email \
    --in-reply-to=a611877f-c515-033c-e015-f3952b520c08@gmail.com \
    --to=tguyot@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=strombrg@gmail.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.
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 NNTP newsgroup(s).