{"thread":{"id":"59668","subject":"Weird merge records","startedAt":"2023-04-28T15:35:09Z","lastAt":"2023-05-08T17:17:09Z","messageCount":8,"participants":["Dan Stromberg","Thomas Guyot","Felipe Contreras"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"476272","messageId":"CAOvKW55oWs+atYyy-cTb=H0VhJx-V+M7_7FsqjdJ_jU9bR+8LA@mail.gmail.com","threadId":"59668","inReplyTo":null,"subject":"Weird merge records","fromName":"Dan Stromberg","fromEmail":"strombrg@gmail.com","sentAt":"2023-04-28T15:34:38Z","receivedAt":"2023-04-28T15:35:09Z","isPatch":false,"sender":{"key":"strombrg@gmail.com","avatar":null},"body":"Hi.\n\nI'm in a development team that has one official repo, and each\ndeveloper has their own repo that is much the same as that official\nrepo - modulo how recently we synchronized them.\n\nI'm getting _many_ Merge records that look like:\n    Merge branch 'develop' of ghosthub.whatever.net:abcd-def/ghij-jk…\n\n...and I don't know where they are coming from.\n\nThe merge records do not appear to show up in 'git log -v'. I only see\nthem in Ghosthub pull requests (Ghosthub being like Github, but\nprivate).\n\nI suspect the merge records may be coming from this small bit of shell\nscript I've been using to pull from the master repo into my personal\nrepo:\n    git fetch upstream\n    git checkout \"$branch\"\n    git config pull.rebase false\n    git pull upstream \"$branch\"\n    git push origin \"$branch\"\n\nDoes that snippet look responsible? If yes, how might I change it to\nstop creating all those merge records? If no, any guesses what else\nmight be causing it?\n\nThanks!\n"},{"id":"476679","messageId":"a611877f-c515-033c-e015-f3952b520c08@gmail.com","threadId":"59668","inReplyTo":"CAOvKW55oWs+atYyy-cTb=H0VhJx-V+M7_7FsqjdJ_jU9bR+8LA@mail.gmail.com","subject":"Re: Weird merge records","fromName":"Thomas Guyot","fromEmail":"tguyot@gmail.com","sentAt":"2023-05-06T14:43:39Z","receivedAt":"2023-05-06T14:45:53Z","isPatch":false,"sender":{"key":"tguyot@gmail.com","avatar":"https://avatars.githubusercontent.com/u/403890?v=4"},"body":"Hi,\n\nOn 2023-04-28 11:34, Dan Stromberg wrote:\n> I suspect the merge records may be coming from this small bit of shell\n> script I've been using to pull from the master repo into my personal\n> repo:\n>      git fetch upstream\n>      git checkout \"$branch\"\n>      git config pull.rebase false\n>      git pull upstream \"$branch\"\n>      git push origin \"$branch\"\n>\n> Does that snippet look responsible? If yes, how might I change it to\n> stop creating all those merge records? If no, any guesses what else\n> might be causing it?\n\nIt is, indeed. This is IMHO something the developers should do \nthemselves, in particular the pull may fail on conflicts and you don't \nseem to stop when it does.\n\nFirst of all, that line:\n\ngit config pull.rebase false\n\n\nYou shouldn't change the user's config - you can instead use \ncommand-line switches with git-pull to force the desired behavior. In \nthis case (which is also the default if there is no pull.rebase config) \nit will merge with the remote (and that merge will be a fast-forward if \nyou have no added commits).\n\nIf you have local commits that aren't on the tip of the remote branch \n(i.e. someone else committed to the branch) you really have only two \noptions here, merge or rebase (there is a new preserve option I think \nthat I'm not familiar with, seems like rebase but preserving local \nmerges). Rebase is the way to avoid merge commits, but conflicts can be \npainful to resolve if you have many commits to push.\n\nAlso note the first fetch is redundant, pull already does a fetch.\n\nSo you could change your script to:\n\n     git checkout \"$branch\"\n     git pull --rebase upstream \"$branch\" || exit 1\n     git push origin \"$branch\"\n\n\nIn the case the pull fails, you will be left with conflicts to resolve - \nthe instructions should be printed on screen and also shown in git-status.\n\nRegards,\n\n--\nThomas\n\n"},{"id":"476728","messageId":"CAMP44s23Qsw3behbm57BNKeT9w_u1OunV04A9uzz85rDcD_Uug@mail.gmail.com","threadId":"59668","inReplyTo":"a611877f-c515-033c-e015-f3952b520c08@gmail.com","subject":"Re: Weird merge records","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-05-07T20:34:30Z","receivedAt":"2023-05-07T20:34:46Z","isPatch":false,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Sat, May 6, 2023 at 10:20 AM Thomas Guyot <tguyot@gmail.com> wrote:\n\n> You shouldn't change the user's config - you can instead use\n> command-line switches with git-pull to force the desired behavior. In\n> this case (which is also the default if there is no pull.rebase config)\n> it will merge with the remote (and that merge will be a fast-forward if\n> you have no added commits).\n\nActually no: it won't merge the current branch with the remote, it\nwill merge the remote with the current branch, which is not the same.\n\nThis is one of the many reasons many git veterans recommend most users\nto simply avoid doing `git pull` [1]: it very rarely does what you\nwant.\n\n[1] https://felipec.wordpress.com/2021/07/13/why-is-git-pull-broken/\n\n-- \nFelipe Contreras\n"},{"id":"476742","messageId":"CAOvKW55MbXF8sDaGTTk9XJxw6Ln9E9G8qOF4wbXzEKY=GH=Zag@mail.gmail.com","threadId":"59668","inReplyTo":"CAMP44s23Qsw3behbm57BNKeT9w_u1OunV04A9uzz85rDcD_Uug@mail.gmail.com","subject":"Re: Weird merge records","fromName":"Dan Stromberg","fromEmail":"strombrg@gmail.com","sentAt":"2023-05-08T14:53:50Z","receivedAt":"2023-05-08T14:54:04Z","isPatch":false,"sender":{"key":"strombrg@gmail.com","avatar":null},"body":"On Sun, May 7, 2023 at 1:34 PM Felipe Contreras\n<felipe.contreras@gmail.com> wrote:\n>\n> On Sat, May 6, 2023 at 10:20 AM Thomas Guyot <tguyot@gmail.com> wrote:\n>\n> > You shouldn't change the user's config - you can instead use\n> > command-line switches with git-pull to force the desired behavior. In\n> > this case (which is also the default if there is no pull.rebase config)\n> > it will merge with the remote (and that merge will be a fast-forward if\n> > you have no added commits).\n>\n> Actually no: it won't merge the current branch with the remote, it\n> will merge the remote with the current branch, which is not the same.\n>\n> This is one of the many reasons many git veterans recommend most users\n> to simply avoid doing `git pull` [1]: it very rarely does what you\n> want.\n\nYou seem to be implying that I shouldn't use 'git pull --rebase\nupstream \"$branch\"'.\n\nIf that's the case, what would you recommend?\n"},{"id":"476743","messageId":"CAOvKW571cxj6XBSBtmUzS-i9w_MfR9p2BOVMHS1Mc3d6CrWO-w@mail.gmail.com","threadId":"59668","inReplyTo":"a611877f-c515-033c-e015-f3952b520c08@gmail.com","subject":"Re: Weird merge records","fromName":"Dan Stromberg","fromEmail":"strombrg@gmail.com","sentAt":"2023-05-08T14:54:22Z","receivedAt":"2023-05-08T14:54:36Z","isPatch":false,"sender":{"key":"strombrg@gmail.com","avatar":null},"body":"On Sat, May 6, 2023 at 7:43 AM Thomas Guyot <tguyot@gmail.com> wrote:\n>\n> Hi,\n>\n> On 2023-04-28 11:34, Dan Stromberg wrote:\n> > I suspect the merge records may be coming from this small bit of shell\n> > script I've been using to pull from the master repo into my personal\n> > repo:\n> >      git fetch upstream\n> >      git checkout \"$branch\"\n> >      git config pull.rebase false\n> >      git pull upstream \"$branch\"\n> >      git push origin \"$branch\"\n> >\n> > Does that snippet look responsible? If yes, how might I change it to\n> > stop creating all those merge records? If no, any guesses what else\n> > might be causing it?\n>\n> It is, indeed. This is IMHO something the developers should do\n> themselves, in particular the pull may fail on conflicts and you don't\n> seem to stop when it does.\n\nIt should stop on an error - because there's a \"set -eu\" in effect.\n\n> Also note the first fetch is redundant, pull already does a fetch.\n>\n> So you could change your script to:\n>\n>      git checkout \"$branch\"\n>      git pull --rebase upstream \"$branch\" || exit 1\n>      git push origin \"$branch\"\n\nI'll keep this in mind.\n\nThanks.\n"},{"id":"476745","messageId":"64590f5430b36_79d229439@chronos.notmuch","threadId":"59668","inReplyTo":"CAOvKW55MbXF8sDaGTTk9XJxw6Ln9E9G8qOF4wbXzEKY=GH=Zag@mail.gmail.com","subject":"Re: Weird merge records","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-05-08T15:03:48Z","receivedAt":"2023-05-08T15:03:55Z","isPatch":false,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Dan Stromberg wrote:\n> On Sun, May 7, 2023 at 1:34 PM Felipe Contreras\n> <felipe.contreras@gmail.com> wrote:\n> >\n> > On Sat, May 6, 2023 at 10:20 AM Thomas Guyot <tguyot@gmail.com> wrote:\n> >\n> > > You shouldn't change the user's config - you can instead use\n> > > command-line switches with git-pull to force the desired behavior. In\n> > > this case (which is also the default if there is no pull.rebase config)\n> > > it will merge with the remote (and that merge will be a fast-forward if\n> > > you have no added commits).\n> >\n> > Actually no: it won't merge the current branch with the remote, it\n> > will merge the remote with the current branch, which is not the same.\n> >\n> > This is one of the many reasons many git veterans recommend most users\n> > to simply avoid doing `git pull` [1]: it very rarely does what you\n> > want.\n> \n> You seem to be implying that I shouldn't use 'git pull --rebase\n> upstream \"$branch\"'.\n\nIf you know what you are doing, then do whatever you want. `git pull --rebase\nupstream $branch` is fine, if you know what that does.\n\nI would just keep in mind that `git pull` wasn't meant to merge your changes to\nupstream, it was meant to merge $branch to your integration branch.\n\n> If that's the case, what would you recommend?\n\nI would recommend `git fetch` + `git rebase` (or merge). If you are explicit\nabout what you want to do, surprises are minimized.\n\n-- \nFelipe Contreras"},{"id":"476753","messageId":"CAOvKW57WdwNoYXJyebMf-V4mQBz5CjvD=qhGxtht_2YKuygL1g@mail.gmail.com","threadId":"59668","inReplyTo":"64590f5430b36_79d229439@chronos.notmuch","subject":"Re: Weird merge records","fromName":"Dan Stromberg","fromEmail":"strombrg@gmail.com","sentAt":"2023-05-08T16:53:54Z","receivedAt":"2023-05-08T16:54:20Z","isPatch":false,"sender":{"key":"strombrg@gmail.com","avatar":null},"body":"On Mon, May 8, 2023 at 8:03 AM Felipe Contreras\n<felipe.contreras@gmail.com> wrote:\n> > You seem to be implying that I shouldn't use 'git pull --rebase\n> > upstream \"$branch\"'.\n>\n> If you know what you are doing, then do whatever you want. `git pull --rebase\n> upstream $branch` is fine, if you know what that does.\n\nI consider myself a git neophyte.  It's a large topic.\n\n> I would just keep in mind that `git pull` wasn't meant to merge your changes to\n> upstream, it was meant to merge $branch to your integration branch.\n\nI see.\n\n> > If that's the case, what would you recommend?\n>\n> I would recommend `git fetch` + `git rebase` (or merge). If you are explicit\n> about what you want to do, surprises are minimized.\n\nMight that look like:\n        git checkout \"$branch\"\n        git fetch upstream\n        git rebase \"$branch\"\n        git push origin \"$branch\"\n?\n\nThanks!\n"},{"id":"476764","messageId":"64592e8e848f2_8a9f294a3@chronos.notmuch","threadId":"59668","inReplyTo":"CAOvKW57WdwNoYXJyebMf-V4mQBz5CjvD=qhGxtht_2YKuygL1g@mail.gmail.com","subject":"Re: Weird merge records","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-05-08T17:17:02Z","receivedAt":"2023-05-08T17:17:09Z","isPatch":false,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Dan Stromberg wrote:\n> On Mon, May 8, 2023 at 8:03 AM Felipe Contreras\n> <felipe.contreras@gmail.com> wrote:\n> > > You seem to be implying that I shouldn't use 'git pull --rebase\n> > > upstream \"$branch\"'.\n> >\n> > If you know what you are doing, then do whatever you want. `git pull --rebase\n> > upstream $branch` is fine, if you know what that does.\n> \n> I consider myself a git neophyte.  It's a large topic.\n> \n> > I would just keep in mind that `git pull` wasn't meant to merge your changes to\n> > upstream, it was meant to merge $branch to your integration branch.\n> \n> I see.\n> \n> > > If that's the case, what would you recommend?\n> >\n> > I would recommend `git fetch` + `git rebase` (or merge). If you are explicit\n> > about what you want to do, surprises are minimized.\n> \n> Might that look like:\n>         git checkout \"$branch\"\n>         git fetch upstream\n>         git rebase \"$branch\"\n\nWith `git rebase` you specify the upstream branch you want to rebase to, so:\n\n  git rebase upstream/master\n\nThis can be configured with the \"upstream tracking branch\" info, so:\n\n  git rebase \"$branch\"@{upstream}\n\nBut this is the default of `git rebase`, so just:\n\n  git rebase\n\n>         git push origin \"$branch\"\n\nIf the branch already exists in the remote, you are probably going to need --force there.\n\nAlso, you don't need to checkout the branch, as `git rebase` can do that for you.\n\nThis is what I would do:\n\n  git fetch upstream\n  git rebase upstream/master $branch\n  git push --force origin $branch\n\nHopefully in this scenario \"upstream\" is the upstream repository and \"origin\"\nis your personal fork.\n\n-- \nFelipe Contreras"}]}