• Ephera@lemmy.ml
    link
    fedilink
    arrow-up
    12
    arrow-down
    1
    ·
    9 days ago

    Very good article for folks who’ve had to teach juniors/trainees Git before.

    This is, to my mind, one of the greatest advantages of git (and, by-the-by, also automated testing): the added security that being able to restore to an earlier state whenever you need to allows you to take more risks and try more things when building software.

    Yeah, I always tell them it’s like checkpoints or like a save in a game.

    But this also ties into the needing-a-teacher aspect to properly learn Git: Due to the nature of what Git accomplishes, it has a lot of complex failure modes. And at the start, you need a teacher to get you through those.

    The worst-case is if they start dreading merges, because they can’t past them and then they try to merge less often, which makes the conflicts so much harder to deal with.
    Or if they can’t get past merge conflicts and stop seeing the point in small Git commits and in good commit messages. That also makes merge conflicts so much worse.

    That’s kind of my motivation to be good at Git. I need to be able to tell juniors, that if they’ve created a commit, then we can unfuck the repo no matter what they might do wrong.

    • okwhateverdude@lemmy.world
      link
      fedilink
      English
      arrow-up
      5
      ·
      9 days ago

      Most projects do not need the complex merging capabilities of git. I’ve found that simply structuring the workflow around trunk based development with linear history works the best: short lived feature branches that get rebased/squashed/committed and the tip of main is always deployable. It avoids dealing with all of the bullshit that comes with long-lived branches and migrating changes between them. This also requires structuring the work itself if you have a larger team so that if you are all working on the same system, avoid crossing the streams (draw some boundaries) to keep dependencies between branches at a minimum. When it starts getting into stacked patches, that’s a good sign you have a kink in the review pipeline somewhere and this complexity can go away with some managering. Git is as complex as you want it to be, and pretty easy to keep it simple

    • lad@programming.dev
      link
      fedilink
      English
      arrow-up
      3
      ·
      9 days ago

      And here we are, encouraged by our technical leadership to always have a single commit per branch that is constantly amended. I even think squashing the branch is not too good, but this is a step up from that

      • Feyd@programming.dev
        link
        fedilink
        arrow-up
        2
        ·
        9 days ago

        Squashing is good because otherwise you have commits that are unreviewed and broken in your main branch which confounds git bisect, which is largely the only time most people even look at commit history

        • lad@programming.dev
          link
          fedilink
          English
          arrow-up
          2
          ·
          9 days ago

          Largely yes, but also having it squashed requires better commit messages and comments to show what was done for what reason. But yes, bisect is the only reason I’m fine with squashing

          • Feyd@programming.dev
            link
            fedilink
            arrow-up
            1
            ·
            8 days ago

            It seems for some reason you assume people have better discipline for commit messages made in the course of a branch that will be merged, but that’s absolutely not true as a general rule. Additionally, even if the squashed commit message is bad, it will at least correspond to a PR in the forge.

        • lad@programming.dev
          link
          fedilink
          English
          arrow-up
          2
          ·
          9 days ago

          If you mean to ask what that means, it’s that for development you start a branch and either do everything in one commit, or do everything in several, but each time you git commit --amend so that a history is overwritten and in the end it is only one commit still