I basically only use git merge like Theo from T3 stack. git rebase rewrites your commit history, so I feel there’s too much risk to rewriting something you didn’t intend to. With merge, every commit is a real state the code was in.

  • zygo_histo_morpheus@programming.dev
    link
    fedilink
    English
    arrow-up
    1
    ·
    2 years ago

    Ideally I’m working on a short lived branch that only I’m working on in which case I do a rebase from origin/master where I also touch up the history in case there are any “forgot x in the previous commit” type of commits before doing a merge request. I won’t rebase code someone else might have pulled, and I’ll quit rebasing if I get any non-trivial conflicts .

  • GitProphet@lemmy.sdf.org
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    2 years ago

    I use rebase only to clean up some commit messages, squash commits, etc. - essentially to clean up feature branches I wrote. But never rebase to ‘move’ my branch as if it originated from a different commit, because I don’t know necessarily know what changes have been introduced on the other branch (typically main/master), so rebasing on that would leave my commits in a state that they were never tested in, possibly broken / with unintended sideeffects. If I need changes from the other (main) branch in my feature branch (because of feature dependencies, or to fix merge conflicts), I merge it into my branch and can be sure that the commits created before that merge still behave the way they did before that merge - because they were not changed; this can’t be said for rebasing.

  • o11c@programming.dev
    link
    fedilink
    English
    arrow-up
    0
    ·
    2 years ago

    The cases where you can use git pull --rebase have high overlap with the cases where git rebase is sane.

    The important thing is when to avoid doing git push --force (almost always; if your remote is a personal fork you theoretically could just create an infinite number of similar branch names for your rebases). Though there are edge cases involving local/SSH clones.

    • Mikina@programming.dev
      link
      fedilink
      English
      arrow-up
      0
      ·
      2 years ago

      What does git pull rebase do? If I understand it correctly, it pulls in the remote changes but rebases your changes to be on top of them, instead of merging the remote and local branch? What is the intended usage of it, it sounds like a lot better way how to pull, why not to use it as default pull?

      • GitProphet@lemmy.sdf.org
        link
        fedilink
        English
        arrow-up
        1
        ·
        2 years ago

        Because rebasing changes the history, which would mess with other people’s copies of the same branch, wherefore it shouldn’t be default.

  • SuperNerd@programming.dev
    link
    fedilink
    English
    arrow-up
    0
    ·
    2 years ago

    Please never rebase after you open a pull request. It breaks the iterative workflow of code reviews – it makes it hard to see if issues brought up in comments were addressed or not.

    • canpolat@programming.devM
      link
      fedilink
      English
      arrow-up
      1
      ·
      2 years ago

      That depends on the PR tool. I don’t know how others work, but Azure DevOps handles rebases quite well (as long as you are rebasing to the target of your PR).