git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 0/3] Reject non-ff pulls by default

From
RHRichard Hansen <rhansen@bbn.com>
Date
Sep 5, 2013, 15:20 UTC
Message-ID
<5228A14B.3000804@bbn.com>
In-Reply-To
<xmqqr4d4jird.fsf@gitster.dls.corp.google.com>
On 2013-09-04 18:59, Junio C Hamano wrote:
Show 21 quoted lines
> "Philip Oakley" <philipoakley@iee.org> writes:
> 
>> From: "Junio C Hamano" <gitster@pobox.com>
>>> John Keeping <john@keeping.me.uk> writes:
>>>
>>>> I think there are two distinct uses for pull, which boil down to:
>>>>
>>>>     (1) git pull
>>> ...
>>> Peff already covered (1)---it is highly doubtful that a merge is
>>> "almost always wrong".  In fact, if that _were_ the case, we should
>>> simply be defaulting to rebase, not failing the command and asking
>>> between merge and rebase like jc/pull-training-wheel topic did.
>>>
>>> We simply do not know what the user wants, as it heavily depends on
>>> the project, so we ask the user to choose one (and stick to it).
>>
>> We only offer a limited list. It won't be sufficient for all use
>> cases. It wasn't for me.
> 
> Very interesting. Tell us more.

I'm a bit late to the discussion, but I wanted to chime in. I detest 'git pull' and discourage everyone I meet from using it. See: <http://stackoverflow.com/questions/15316601/why-is-git-pull-considered-harmful> for my reasons.

Instead, I encourage people to do this:
   git config --global alias.up '!git remote update -p; git merge
--ff-only @{u}'

and tell them to run 'git up' whenever they would be tempted to use a plain 'git pull'.

I usually work with a central repository with topic branches.  I follow
this rule of thumb:
  * When merging a "same-named" branch (e.g., origin/foo into foo, foo
    into origin/foo), it should always be a fast-forward.  This may
    require rebasing.
  * When merging a "differently-named" branch (e.g., feature.xyz into
    master), it should never be a fast-forward.

In distributed workflows, I think of 'git pull <collaborator-repo> <their-branch>' as merging a differently-named branch (I wouldn't be merging if they hadn't told me that a separate feature they were working on is complete), so I generally want the merge commit. But when I do a 'git pull' without extra arguments, I'm updating a same-named branch so I never want a merge.

When merging a differently-named branch, I prefer the merge --no-ff to be preceded by a rebase to get a nice, pretty graph:

       * merge feature.xyz  <- master
       |\
       | * xyz part 3/3
       | * xyz part 2/3
       | * xyz part 1/3
       |/
       * merge feature.foo
       |\
       | * foo part 2/2
       | * foo part 1/2
       |/
       * merge feature.bar
       |\
       ...
The explicit merge has several benefits:
  * It clearly communicates to others that the feature is done.
  * It makes it easier to revert the entire feature by reverting the
    merge if necessary.
  * It allows our continuous integration tool to skip over the
    work-in-progress commits and test only complete features.
  * It makes it easier to review the entire feature in one diff.
  * 'git log --first-parent' shows a high-level summary of the changes
    over time, while a normal 'git log' shows the details.
> 
> When "git pull" stops because what was fetched in FETCH_HEAD does
> not fast-forward, then what did _you_ do (and with the knowledge you
> currently have, what would you do)?
I stop and review what's going on, then make a decision:
  * usually it's a rebase
  * sometimes it's a rebase --onto (because the branch was
    force-updated to undo a particularly bad commit)
  * sometimes it's a rebase -p (because there's an explicit merge of a
    different branch that I want to keep)
  * sometimes it's a reset --hard (my changes were made obsolete by a
    different upstream change)
  * sometimes it's a merge
  * sometimes I do nothing.  This is a fairly regular pattern:  I'm in
    the middle of working on something that I know will conflict with
    some changes that were just pushed upstream, and I want to finish
    my changes before starting the rebase.  My collaborator contacts me
    and asks, "Would you take a look at the changes I just pushed?"  If
    I type 'git pull' out of habit to get the commits, then I'll make a
    mess of my work-in-progress work tree.  If I type 'git up' out of
    habit, then the merge --ff-only will fail as expected and I can
    quickly review the commits without messing with my work tree or
    HEAD.

Even if I always rebase or always merge, I want to briefly review what changed in the remote branch *before* I start the rebase. This helps me understand the conflicts I might encounter.

Thus, ff-only always works for me. I might have to type a second merge or rebase command, but that's OK -- it gives me an opportunity to think about what I want first. Non-ff merges are rare enough that the interruption isn't annoying at all.

> In a single project, would you
> choose to sometimes rebase and sometimes merge, and if so, what is
> the choice depend on?  "When I am on these selected branches, I want
> to merge, but on other branches I want to rebase?"

My choice depends on the circumstances of the divergence. It's never as simple as branch X always has this policy while branch Y has that policy.

Show 7 quoted lines
> Are there cases where you do not want to either rebase nor merge?
> If so what do you want to do after "git pull" fetches from the other
> side?  Nothing?
> 
> 	Side note: a knee-jerk response to a "yes" answer to the
> 	last question from me has always been "then why are you
> 	running 'git pull' in the first place.
Habit/muscle memory/I'm tired and not thinking 100% clearly.
-Richard
Previous: John SzakmeisterNext: Philip Oakley
Message 73 of 84 in “Reject non-ff pulls by default”
  1. 0/3 Reject non-ff pulls by defaultFelipe Contreras, Aug 31, 2013
  2. 1/3 merge: simplify ff-only optionFelipe Contreras, Aug 31, 2013
  3. 2/3 t: replace pulls with mergesFelipe Contreras, Aug 31, 2013
  4. 3/3 pull: reject non-ff pulls by defaultFelipe Contreras, Aug 31, 2013
  5. Junio C HamanoSep 3, 2013
  6. Felipe ContrerasSep 3, 2013
  7. Junio C HamanoSep 3, 2013
  8. Felipe ContrerasSep 3, 2013
  9. John KeepingSep 4, 2013
  10. Jeff KingSep 4, 2013
  11. John KeepingSep 4, 2013
  12. Felipe ContrerasSep 8, 2013
  13. Jeff KingSep 8, 2013
  14. Felipe ContrerasSep 8, 2013
  15. Jeff KingSep 8, 2013
  16. Felipe ContrerasSep 8, 2013
  17. Jeff KingSep 8, 2013
  18. Felipe ContrerasSep 8, 2013
  19. Jeff KingSep 8, 2013
  20. Felipe ContrerasSep 8, 2013
  21. Jeff KingSep 8, 2013
  22. Felipe ContrerasSep 8, 2013
  23. Jeff KingSep 9, 2013
  24. Felipe ContrerasSep 9, 2013
  25. John KeepingSep 8, 2013
  26. Jeff KingSep 9, 2013
  27. brian m. carlsonSep 8, 2013
  28. Felipe ContrerasSep 8, 2013
  29. brian m. carlsonSep 9, 2013
  30. Felipe ContrerasSep 9, 2013
  31. Felipe ContrerasSep 9, 2013
  32. brian m. carlsonSep 9, 2013
  33. Matthieu MoySep 9, 2013
  34. Junio C HamanoSep 9, 2013
  35. Jeff KingSep 9, 2013
  36. John KeepingSep 9, 2013
  37. Jeff KingSep 9, 2013
  38. John KeepingSep 9, 2013
  39. Richard HansenSep 9, 2013
  40. Matthieu MoySep 9, 2013
  41. Jeff KingSep 9, 2013
  42. Philip OakleySep 9, 2013
  43. Felipe ContrerasSep 9, 2013
  44. John KeepingSep 10, 2013
  45. Matthieu MoySep 9, 2013
  46. Junio C HamanoSep 10, 2013
  47. Felipe ContrerasSep 9, 2013
  48. Matthieu MoySep 10, 2013
  49. Felipe ContrerasSep 11, 2013
  50. Matthieu MoySep 11, 2013
  51. Felipe ContrerasSep 13, 2013
  52. Junio C HamanoSep 4, 2013
  53. Junio C HamanoSep 4, 2013
  54. Philip OakleySep 4, 2013
  55. Junio C HamanoSep 4, 2013
  56. John KeepingSep 5, 2013
  57. Junio C HamanoSep 5, 2013
  58. John KeepingSep 5, 2013
  59. Jonathan NiederSep 6, 2013
  60. Junio C HamanoSep 6, 2013
  61. John KeepingSep 7, 2013
  62. Felipe ContrerasSep 8, 2013
  63. Felipe ContrerasSep 8, 2013
  64. Philip OakleySep 8, 2013
  65. Felipe ContrerasSep 8, 2013
  66. Philip OakleySep 8, 2013
  67. Felipe ContrerasSep 8, 2013
  68. Philip OakleySep 8, 2013
  69. Philip OakleySep 8, 2013
  70. John SzakmeisterSep 5, 2013
  71. John KeepingSep 5, 2013
  72. John SzakmeisterSep 5, 2013
  73. Richard HansenSep 5, 2013
  74. Philip OakleySep 5, 2013
  75. Junio C HamanoSep 5, 2013
  76. Junio C HamanoSep 5, 2013
  77. Felipe ContrerasSep 8, 2013
  78. Richard HansenSep 8, 2013
  79. Junio C HamanoSep 8, 2013
  80. Richard HansenSep 8, 2013
  81. Philip OakleySep 8, 2013
  82. Felipe ContrerasSep 8, 2013
  83. Ramkumar RamachandraSep 8, 2013
  84. Greg TroxelSep 5, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.