Git MERGE vs REBASE: Everything You Need to Know

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ก.ย. 2024
  • Get a Free System Design PDF with 158 pages by subscribing to our weekly newsletter: bytebytego.ck....
    Animation tools: Adobe Illustrator and After Effects.
    Checkout our bestselling System Design Interview books:
    Volume 1: amzn.to/3Ou7gkd
    Volume 2: amzn.to/3HqGozy
    The digital version of System Design Interview books: bit.ly/3mlDSk9
    ABOUT US:
    Covering topics and trends in large-scale system design, from the authors of the best-selling System Design Interview series.

ความคิดเห็น • 340

  • @Haitaish
    @Haitaish ปีที่แล้ว +791

    2 minutes into the video and animations help understand rebase 1000x better than any static explanation on any website ever could.
    Thank you.

    • @z0nx
      @z0nx ปีที่แล้ว +8

      this is what you see happening when using a gui like fork

    • @Dmittry
      @Dmittry ปีที่แล้ว +7

      @@z0nx Using GUI help to understand the process much better. I agree.

    • @gerdsfargen6687
      @gerdsfargen6687 ปีที่แล้ว

      So well put.

    • @olezhonnv3215
      @olezhonnv3215 ปีที่แล้ว +1

      Yes, great video!

    • @mohamedr1164
      @mohamedr1164 8 หลายเดือนก่อน +1

      Git rebase rewrite history and rewrite history is evil

  • @mhopado
    @mhopado ปีที่แล้ว +110

    My workflow
    1. Create a feature branch.
    2. Keep pulling and rebasing the changes from the main branch cmd : git pull -- rebase
    3. Once done with my features, squash all commit to one
    4. Merge the features branch into main

    • @Daddyjs
      @Daddyjs 4 หลายเดือนก่อน +7

      This is the best way

    • @Spanakopitaa
      @Spanakopitaa 4 หลายเดือนก่อน

      whoever does not do this, you have serious mental issues

    • @seyadeodin
      @seyadeodin หลายเดือนก่อน

      Hello, could you explain what the second step is for? Avoid conflicts when merging?

    • @BeadzW
      @BeadzW หลายเดือนก่อน

      Rebasing from main to feature ie tracking every commit in Main, on his branch. That’s what I understand might be wrong also

    • @thomasluk4319
      @thomasluk4319 หลายเดือนก่อน

      @@BeadzWhow come it’s wrong

  • @sperrfeuer4158
    @sperrfeuer4158 11 หลายเดือนก่อน +229

    There's a reason merging squash commits is so popular, and that's because it's the easiest and most compatible with how most people use git. Most people want their branch to be their own workspace, and while in some kind of fantasy world each commit would be filled with very useful information, in reality it's mostly swear words and short notes. Having squash commits and PRs can force developers to write a longer, better description of their entire feature when merging instead, and get rid of all the mostly scattered and hard to understand commits from the feature branch. The only people I've ever met that prefer rebasing are people who live and breathe git and feel like every commit is sacred, but this is an incredibly tedious way to work -- if your features are so large that you feel that the history of a hundred commits is necessary, just make smaller features, or better yet, actually comment your code like you're supposed to.

    • @kinkajou2310
      @kinkajou2310 10 หลายเดือนก่อน +4

      This is exactly why looked up this video, I have weird commit messages and some commits that I don't want to appear in the main history (fixing typos for example).

    • @sperrfeuer4158
      @sperrfeuer4158 10 หลายเดือนก่อน +5

      @@kinkajou2310 interactive rebasing is a great use case for squashing your own commits, but when following the process I just described it also doesn't matter much since *all* commits will disappear when the feature branch is merged into "dev" or whatever anyway. There are obviously use cases for not using merge commits ("release merges" from dev -> main are one of them), but rebases are also inherently more dangerous since they, unlike merging, can lead to losing your history completely if you're sloppy when resolving merge conflicts.

    • @_grigoryta
      @_grigoryta 10 หลายเดือนก่อน +8

      Instead of writing swear words and short notes before making a PR one could split up their work into meaningful chunks by soft-resetting their branch and staging important bits of code into their own meaningful parts. Or better yet, start by doing exactly that at the very beginning of the feature development. For example.
      • Task#69: Implemented tests for feature whatever
      |
      • Task#69: Implemented admin tools to control feature whatever
      |
      • Task#69: Implemented main business logic for feature whatever ## (this is where the soft-reset probably happened)
      |
      • Task#69: Refactored some stuff to make implementeation of feature whatever less painful/more better etc ## (the actual start of feature development)
      It's your own branch, you can make it as pretty as you want it. And others can appreciate all the logically split bits instead of trying to makes sense of all the "wip", "some shit i did here" and "bubble sort or something, idk, i'm not a programmer" commits during code review.
      It's always faster to review individual commits when they make sense instead of staring at the wall of code. At least for me
      P.S. I'm rebase and fastforward guy all the way btw. But you gotta clean up your commits first. Even if you'll squash them into one

    • @cesarrios4201
      @cesarrios4201 8 หลายเดือนก่อน +1

      The best explanation I found.

    • @theIbraDev
      @theIbraDev 8 หลายเดือนก่อน +3

      Sounds like a skillissue to me. Clear comitts and comments are an essential part of documentation.

  • @AlbertLeng
    @AlbertLeng ปีที่แล้ว +103

    One of the best channels to learn about sw technologies. No fluff talks, no distracting music, no ads, pure substance with straight to the point explanations and amazing animation!

    •  ปีที่แล้ว +5

      And in an infectiously peaceful way. Amazing!

    • @RobertPodosek
      @RobertPodosek ปีที่แล้ว +4

      I really want to know how they do all their animations!

  •  ปีที่แล้ว +57

    Tried various strategies and so far I prefer to always work with merge commits and almost no rebase (unless the branch was never published).
    Merge from main branch to feature branch.
    Merge from feature branches to master when ready, no squash, no fast forward, always creating a merge commit.
    I don't find the history messy as it's exactly as development happened.
    Remember that you can always see history with --first-parent if you want to see only a commit (similar with how squash result can be viewed).

    • @ultrastoat3298
      @ultrastoat3298 4 หลายเดือนก่อน +3

      I've read (and experienced) that reabase can actually create havoc when other people have the branch on their machines. It is the most attractive solution though because it makes reviews easy. You don't see noise from the parent branch on your feature branch. Its too bad that Git's implementation allows for this attractive intuitive feature to be risky.

  • @Dmittry
    @Dmittry ปีที่แล้ว +111

    We *squash* our personal PRs and *merge* our team branch to main. To update my branches I prefer *rebase* . But rebase is not so good if several people work on the same branch.

    • @DemPilafian
      @DemPilafian ปีที่แล้ว +9

      Git rebase is very safe. It's like Russian Roulette -- you have a significantly greater than 80% chance of surviving.

    • @amanshrivastava3391
      @amanshrivastava3391 ปีที่แล้ว

      Our team follows the same plus when we need to sync main into other feature branches we use merge fast forward

    • @dale3478
      @dale3478 ปีที่แล้ว +13

      One time I had to work with 1 or 2 other people in the same branch, because that's what we deploy to staging to test our features. It's quite messy, and when I want to deploy my changes, there were some conflicts, so I decided to rebase the staging branch from my feature branch because somehow the resolution is simpler, and force push it to staging. All good. Then after some time, my teammate asked me: "hey, did you delete my changes?". Turns out my local branch was outdated.
      So yeah, don't rebase a shared branch. Or probably, don't force push a shared branch, which is what you'd need to do when rebasing

    • @Dmittry
      @Dmittry ปีที่แล้ว +6

      @@dale3478 Yes, if you work on the branch alone, then rebasing is the best option I think. Very clean.
      But if someone else also works on the same branch things become more complicated. You should be very careful with impact on others. And Pull, Pull, Pull 😁

    • @etexas
      @etexas ปีที่แล้ว

      I don't understand. If you squash before rebase to main, what is the problem?

  • @jamoncitovideos
    @jamoncitovideos ปีที่แล้ว +41

    One major advantage of using rebase instead of merge that is not mentioned in the video: when two developers work on different feature branches in parallel, when merging git will mix up the commits of each branch, so it's easy to break someone else's code. As an example, dev1 makes commit A at 9am and commit B at 11am, while dev2 makes a commit in a different branch at 10am. When merging both features, git tries to combine the 3 commits in this order: A, C, B. This mix up makes it easy to break code and merge conflicts become a mess. With rebase&fast-forward, the commits will be seen as A, B, C (or C, A, B if dev2 made the PR first). Just because the changes from both branches were committed in parallel, it does not mean that the logic in the code evolution follows the same logic, as the features were independently developed.
    Hope that was clear enough - I feel like I didn't explain myself that well :')
    To the creators: Great video! Could I suggest making an explanatory video on how to work with forks as a follow-up? I've been recently taught this together with rebase+squash by a senior dev & it has made my workflow so much better!!!

    • @UTJK.
      @UTJK. ปีที่แล้ว +1

      The explanation is perfect. And thanks for adding this to the conversation.

    • @jordanconner6946
      @jordanconner6946 ปีที่แล้ว +1

      "when merging both features" - hopefully you're not actually talking about merging 2 feature branches into a main branch with 1 command, which is referred to as an "octopus" merge. I'm going to assume you're not, because in your rebase example you talk about whoever made the PR first. Confusing comment, because there is never a case where a conflict is handled any different in a merge vs a rebase - unless you're referring to an "octopus" merge which should never be done anyways (and isn't if pull requests are being utilized).

    • @chandrasekarank8583
      @chandrasekarank8583 ปีที่แล้ว +1

      Yes whoever made a PR first their commits will be merged first

    • @UMESHTOKE
      @UMESHTOKE ปีที่แล้ว

      I think it won't matter who merges their branch to main branch as the commits will rewritten according to the timeline (In case of rebase). In above case A'->C'->B' as C was commited before B but in case of merge it's gonna be A-C-B--. Correct me if you think otherwise.

    • @DK-ox7ze
      @DK-ox7ze ปีที่แล้ว +1

      So in your example if we do git log after merge, it will show commits in this order :B, C, A?

  • @emekaokezie4251
    @emekaokezie4251 ปีที่แล้ว +8

    Updating my main branch, I prefer working with GIT MERGE. It feels a lot more straightforward for me more importantly is the fact that I can track my commit history when I make use of the MERGE option.

  • @hello_world_zz
    @hello_world_zz ปีที่แล้ว +7

    Alex, you truly are the epitome of excellence. With my 15 YOU as a SWE, I can confidently say that collaborating with someone of your calibre has undoubtedly been the utmost highlight in my professional journey.

    • @sergiocoder
      @sergiocoder 3 หลายเดือนก่อน +1

      He's not Alex though

  • @Furki4_4
    @Furki4_4 ปีที่แล้ว +8

    I've never used rebase and squash techniques but i like the way they combine the commits in the feature branches to the main branch. Thank you ❤

  • @Clem.E
    @Clem.E ปีที่แล้ว +4

    With Git rebase, I find myself rebasing more often on the main branch in order to prevent the branch from diverging to much. It has the benefit of avoiding too many conflicts on the final rebase.

  • @alexeibrinza2719
    @alexeibrinza2719 ปีที่แล้ว +7

    I prefer the hybrid approach. First create a new feature branch from main branch. Add a few commits on feature branch. If the commits all belong to the same task or represent the same feature, fixup/squash them. If each commit represents distinct functionality or it makes sense to revert a part of the feature, not the whole feature, then don't use fixup/squash. After the work is done - rebase the branch with the main. Using this technique, you can combine both squash/rebase as needed.

  • @VincentJenks
    @VincentJenks 11 หลายเดือนก่อน +1

    Ah, The Great Debate. I’ve hunkered around many a whiteboard and heard endless iterations of passionate arguments for all approaches. Regardless of what you personally prefer, it all comes down to the project, your team, and what works for everyone. There’s no hard and fast rule and all approaches have their merit.

  • @cerio3237
    @cerio3237 4 หลายเดือนก่อน +2

    Wow. I've watched some of your videos and they are MASTERPIECES. You put a lot of work into these videos and it's great! Keep up the great work!

  • @kevalan1042
    @kevalan1042 ปีที่แล้ว +33

    The squash approach makes sense to me, you can see the whole change at once and the full detail in the branch if needed

    • @prathameshbhat9816
      @prathameshbhat9816 ปีที่แล้ว +1

      It creates new hash though

    • @Backtrack3332
      @Backtrack3332 ปีที่แล้ว

      ​@@prathameshbhat9816Thats great imo, you can easily cherry pick a squashed commit

    • @kevalan1042
      @kevalan1042 ปีที่แล้ว +1

      @@prathameshbhat9816 why is that an issue?

    • @prathameshbhat9816
      @prathameshbhat9816 ปีที่แล้ว

      @@Backtrack3332 reverse merges from prod to testing environment

    • @stereodark
      @stereodark ปีที่แล้ว +3

      If you use sub modules it can screw up some build dependencies

  • @carlonnrivers
    @carlonnrivers ปีที่แล้ว +20

    I git merged all my life because rebase was scary from my knowledge of it, and i never knew about squash.
    Now thanks to this video, rebase sounds like it makes sense now. Squash is the scary one because I could lose version history. But it's good to know that history will be preserved in the other branches.

    • @B20C0
      @B20C0 ปีที่แล้ว +1

      The question is: How often to you look at the history of individual commits in a feature branch? I've learned that barely anyone does that. And even if some fatal flaw is found nobody looks back and tries to figure out what happened but instead it's usually fixed in yet another hotfix branch.

    • @KazzyJr
      @KazzyJr ปีที่แล้ว +3

      Rebasing looks good at first, but improperly done leads to a big headache due to the history being rewritten. Went through this and it's not a fun time. Squashing is actually the best of both worlds, you lose the fine detail of commits but it all gets merged into one commit and one big message. You can always see it afterwards, it's just harder to read. I only rebase local branches on the main one before I've done any commits on them, which is usually very early on after branch creation when a colleague merges a PR.

    • @NghiaTran-er5mp
      @NghiaTran-er5mp ปีที่แล้ว +1

      If your feature branches follow the single principle well the squash will make more sense after all.

    • @dinov5347
      @dinov5347 ปีที่แล้ว +1

      I have the same view. We used to rebase at one point in the past but it was very problematic if there was an issue so we gave up (worked well if there were no problems). With merge, there is basically zero chance of screwing up the code base.

  • @tushar8133
    @tushar8133 ปีที่แล้ว +4

    Believe me, you always make us clear long due complex topics in a single shot. I have been trying to figure out this topic for the past few years, but never understood. Thanks a lot! We ❤ your channel.

  • @orterves
    @orterves ปีที่แล้ว +2

    Rebase and merge ("semi-linear merge" - not fast forward!) is superior for cleaner change information. I call it the "knotted-rope".
    After rebasing but before merging, I frequently reset soft and selectively commit the files in sets with messages that best describe what was done, in way that ensures each commit builds on the last. Sometimes it's necessary to commit partial file changes or even adjust the changes directly to better express a 'sub-commit'.
    You can always compare the resulting refactoring with the original rebased branch head commit to confirm the sum total is the same, so there's no risk of losing changes with this approach.
    What you end up with is clean, readable sets of delineated commits that are useful for future investigation into the history of changes - while still allowing the development process to be continuously committing to a branch without too much concern for the messages or presentation of the commits. It's a nice have your cake and eat it too approach

  • @sahajmalla
    @sahajmalla 4 หลายเดือนก่อน

    We do this:
    - Create a feature branch from main
    - do works in feature branch
    - and while doing PRs to main/dev, we squash commits into one and do PR.
    - merge the PR to main/dev
    This makes the commit history clean and we are really fan of it.
    However, while doing this, we make sure that the team knows how git rebase works and how commit hash are changed when sqashing/rebasing so that we won't have to deal with weird commit hash mismatch issues.
    Another thing that we widely use is the interactive mode of rebase. We use it from picking, rewording, squashing, editing, and fixing commits.

  • @aaraz101
    @aaraz101 11 หลายเดือนก่อน +2

    This guy graphics is always the best to understand and remember , thanks man !!

  • @esra_erimez
    @esra_erimez ปีที่แล้ว +3

    These animations really facilitate the meaning of these concept in a clear and concise manner. Thank you.

  • @MrZiyak99
    @MrZiyak99 ปีที่แล้ว +9

    I used to rebase the main branch into my feature branch. the issue with that which not many talk about is that if you're too many commits behind you'll be forced to fix merge conflicts on a commit by commit basis. i usually prefer merging now and then user interactive rebase to pick commits in my feature branch before pushing to main

    • @Spanakopitaa
      @Spanakopitaa 4 หลายเดือนก่อน +1

      that's why you do not need to have too many commints on your feature branch, squash them to one or two at most

  • @jmwild1
    @jmwild1 ปีที่แล้ว +10

    This is a great visual summary of each. I was always skeptical of using rebase and always merged with local commits before pushing my changes. But I think I like rebase conceptually better, I might start getting into the habit of using rebase in the future.

  • @jmbrjmbr2397
    @jmbrjmbr2397 4 วันที่ผ่านมา

    Gorgeous video, you expleained the terms so clear. Thank you!

  • @Oda3908
    @Oda3908 ปีที่แล้ว +7

    main -> feature = rebase
    feature -> main = squash + merge
    rebase would be painful if the feature branch existed too long, you need to resolve conflicts from the oldest commit to the latest one(standard mode), squashing commits in the feature branch can improve the rebase experience, personally a better solution is to make a smaller task and PR.

  • @techsuvara
    @techsuvara 3 หลายเดือนก่อน

    Rebase is rarely used now with CD, we make most commits on main, no feature branches.
    Additionally, I’ve had plenty more merge problems when rebasing on to main.
    Very rarely does anyone look at merge history, but we do use our merge history to generate release notes.

  • @julienwickramatunga7338
    @julienwickramatunga7338 ปีที่แล้ว +2

    Very nice video, short and insightful!
    Thank you for reminding us that as anything in IT (and in life really), choosing a Git strategy is about pros and cons, and is specific to a given context.
    No strategy is better than another, there just tools for teams to use, to get the job done.
    Have a nice day!

  • @maxspielberg6612
    @maxspielberg6612 4 หลายเดือนก่อน

    This was more helpful than i can explain. I am collaborating on github for the first time and didnt know what any of the differences were and just had a terrible day merging changes when i should have rebased. Everything makes perfect sense now.

  • @swedishpsychopath8795
    @swedishpsychopath8795 11 หลายเดือนก่อน +2

    This guys explanation wasn't too bad, I guess. Thank you!

  • @jitendrapatidar3791
    @jitendrapatidar3791 หลายเดือนก่อน

    After seeing your video, I am try to using rebase over merge before it I am using merge.
    thank you
    😀🤩

  • @enistoteles
    @enistoteles ปีที่แล้ว +2

    Sir, your videos are just perfect. Keep the good work up, cant have enough of it.

  • @ForestValleyGame
    @ForestValleyGame ปีที่แล้ว +4

    I prefer merging. Although it has ugly merge commits, I've never had any problems with it in the contrary with rebasing and squashing.

    • @srki22
      @srki22 ปีที่แล้ว

      Yeah, I always merge. Clean history is overrated because you can always filter commits that have a pull request in the message so you get clean merge history of the main branch

  • @JimmyS2
    @JimmyS2 หลายเดือนก่อน

    I use Rebase only on my local branches, like i want to rebase my feature branch onto my local main before i push to remote, but i prefer merge when pulling changes from remote to my local branches because we have several outsource teams working with us, some CRs have decencies or code that conflicts with the local branch, that's why i use merge because i get to see the history and compare the changes until i find the commit causing the merge conflict.

  • @AndreasToth
    @AndreasToth 8 หลายเดือนก่อน +2

    The flowchart at 04:10 is brilliant.

  • @mariuszkos1989
    @mariuszkos1989 หลายเดือนก่อน

    3 minutes and now I understand everything, thank you

  • @prabhavathipulaparthi6686
    @prabhavathipulaparthi6686 5 หลายเดือนก่อน

    My approach
    1. Have a default and master branch and both are protected branches and both the branches will always be in sync.
    2. Create Feature branch for each feature from dev_master.
    3. Merge all the features into dev_master
    4. Merge dev_master into master

  • @teeesen
    @teeesen 10 หลายเดือนก่อน

    What a great video! Here is why I ask my team to avoid rebases and squashes. Sometimes I look back at the history for dead ends, i.e. commits with no descendants. Without rebases and squashes these generally fit one of three categories. (A) Work that later turned out not be needed, (B) work that is on-going and hasn’t yet gone into a merge request, and (C) work that should have gone into a merge-request, but didn’t. Hopefully the first category is rare. Rebase and squash create new commits and the older versions of those commits are left in the repository without descendents. That creates another category of commits without descendants: (D) useful work that was replicated elsewhere. It’s often hard to distinguish (D) from (B) and (C). Far from having a clean history, you have a messy history with a lot of dead ends and commits that replicate work on other commits. Well that’s how I see it, but I’m interested in reading the comments to see why others like rebasing and squashing.

  • @Primalmoon
    @Primalmoon ปีที่แล้ว +1

    Working in a large monorepo, rebasing and squashing is essentially required... without it the branch history quickly becomes a tangled mess, as you end up with many many more merge commits than actual code commits, and then the rest of the commits are a few thousand commits from one developer that was following the TDD practice of making a new commit every time the tests were passing. As long as you can convince people to squash the history can remain readable. And rebasing helps keep the amount of catastrophic merge conflicts to a minimum by not squashing in the same commits that someone else is merging, which will be happening all the time in an active repo.

  • @kingsleyzuze9949
    @kingsleyzuze9949 ปีที่แล้ว +1

    I basically just use git merge, but I think I'll try git squash more as I sometimes have multiple branches feeding into main - thank you for this one.

  • @juliahuanlingtong6757
    @juliahuanlingtong6757 3 หลายเดือนก่อน

    Crystal clean explanation on the each values different models emphasize!
    To better understand how to navigate potential challenges effectively, would it be possible for us to delve into depth of solutions and best practices aimed at mitigating the drawbacks associated with each approach with the exploring hypothetical worst-case scenarios? Looking forward to it.

  • @Sranju23
    @Sranju23 ปีที่แล้ว +1

    Thank you, for covering the topic that always gives me little anxiety while executing those commands 😃

  • @sergiocoder
    @sergiocoder 3 หลายเดือนก่อน

    I usually do rebase + squash in my projects.
    But if a branch has some commits that I would like to keep unsuqashed, e.g. a code change that was later undone in the same branch but I think it might be useful in the future, I'd use a merge (without fast-forward).

  • @jackgunn1480
    @jackgunn1480 หลายเดือนก่อน

    Excellent overview, with excellent graphics. I get it now.

  • @mariagutkovskaya2330
    @mariagutkovskaya2330 3 หลายเดือนก่อน

    The best explanation I have ever seen🔥

  • @frederik_hd
    @frederik_hd ปีที่แล้ว +1

    when there is a merge conflict I usually rebase my feature branch - and after development I create a PR with an clean and clear git history means combining commits and checking git messages - and the merge into the main branch I always use squash commit

  • @DanelonNicolas
    @DanelonNicolas ปีที่แล้ว +1

    I love to update my branches and the merge them to master using squash haha. I love this channel. my new favourite of this year haha❤

  • @reza_majidi
    @reza_majidi ปีที่แล้ว +1

    I personally use rebase before merging my feature branch to staging. In this way every merge conflicts will be resolved in my branch before merge. I also occasionally rebase to staging to get the latest changes.

    • @s_stefaniv
      @s_stefaniv ปีที่แล้ว

      This is how I work on data analytics projects. It works well for me and my collegues

  • @minlaxz
    @minlaxz ปีที่แล้ว

    I used both, MERGE and REBASE.
    Sometimes, it's better to leave a history (merge commit), since it's easier to be tracked.
    But sometimes, I used 'rebase', where I don't need to track anything.

  • @judgewest2000
    @judgewest2000 หลายเดือนก่อน

    Thank you so much for this video. Just incredibly clear!

  • @funkynerd_com
    @funkynerd_com ปีที่แล้ว +1

    I'm probably doing it wrong, but there's two projects I work on and do it differently on each. One project is with a small team of 3 developers and we only merge. Commit history is not "messy" due to the size of the team and feature concurrency, but we get tonnes of detail which is helpful when tracking down regressions. My other project though, I use squash commits. Gitlab does a good job of building commit messages out of the feature commit history so I don't really lose anything. Main history is cleaner, etc.

  • @matk2283
    @matk2283 6 หลายเดือนก่อน

    Amazing tutorial on rebase and squash. I loved the animation which gives you the exact operation of each right in front of your eyes. My gratitude to you for explaining all that.
    much appreciated my dear friend !!

  • @MrGreg557
    @MrGreg557 ปีที่แล้ว +1

    Great video. It's also good to note that git rebase is a form of rewriting history. This means that it should be used much more carefully when you work with other people on the same feature branch. Anyway, I personally used git merge + rebase with squash on main most often in many organizations..

    • @dave6012
      @dave6012 ปีที่แล้ว

      I’m still yet to come across an issue using the rebase+squash strategy, so I really can’t see any reason not to use it. IMO a feature shouldn’t be picked apart after merge, just wholly reverted and fixed and remerged. Rarely could I revert a single commit from my feature branch (e.g. to resolve a bug after merge to main), and not have it break the feature entirely.

  • @zshn
    @zshn ปีที่แล้ว

    Git rebase is a nightmare in a large team working on same files. Developers spent time resolving conflict on their local and then in production. Without context, fully backed unit tests and collaboration it can easily create a mess. 1 dev renaming a function while the 2 other devs changing the contents of the function. Now multiply that. Git merge is my preferred approach. We have a main branch, develop branch and feature branches. We git merge from feature to develop on a daily basis and git rebase and squash commit from develop to main on a release basis.

  • @HassanUmari
    @HassanUmari 4 หลายเดือนก่อน

    I prefer git rebase.
    When there conflicts, both commands might require the manual resolve. If a merge fails, a rebase will too! and vice versa.
    So the actual difference is, who should resolve the conflicts when submitting a merge request / pull request? the author of the feature branch, or the maintainer/reviewer?
    When conflicts arise, it makes more sense to let the author of the feature branch resolve those commits, not the maintainer/reviewer. Since the author is more aware of the changes introduced in the feature branch.
    The second benefit is the one you mentioned regarding linear git history when using rebase.

  • @chezchezchezchez
    @chezchezchezchez 21 วันที่ผ่านมา

    I’m a big fan of the rebasing.
    In the 70s, we did a lot of freebasing, and this is much safer.

  • @MichaelScharf
    @MichaelScharf ปีที่แล้ว +1

    I use rebase to squash 20-50 small commits on my feature branch into a few meaningful ones before merging. I typically commit up to 10 times an hour.

  • @iHariPatel
    @iHariPatel ปีที่แล้ว +1

    I been using merge only , now I understood rebase is good idea for clean history

  • @filipstojiljkovic4711
    @filipstojiljkovic4711 ปีที่แล้ว

    Excellent video, however I feel like squash is not in the same category as rebase and merge (which video may confuse people of being so), its more of a strategy of how we merge our final changes to the main branch, and not how we keep track of main branch with our feature branch. I think if solo using feature branch, rebase is the best way to go, after which you merge PR with squashed commits.

  • @sameershah141
    @sameershah141 ปีที่แล้ว +2

    The animation visualisation is great!!!

  • @jorden123
    @jorden123 ปีที่แล้ว

    Rebase whenever you want to get your feature branch in sync with main, when done implementing - squash, tag and merge into main.

  • @chrismarois4349
    @chrismarois4349 6 หลายเดือนก่อน

    I have my team rebase feature branches. I find it easy to use merge the wrong way and end up having the same commits into multiple branches and have a merge nightmare at the end. I want a linear history.
    I also promote a good git hygene, we work with Jira and basically try to end up with 1 commit per ticket. This is basically using rebase interactive on your branches and squash your commits within your branches. That way if you end up having conflicts to resolve, instead of going through 30 commits, you go through 1 only, and often you basically avoid a conflict altogether.

  • @kurochkin1
    @kurochkin1 หลายเดือนก่อน

    amazig video, u spend your time and save our time, greate deal. thx

  • @piotrmazgaj
    @piotrmazgaj 22 วันที่ผ่านมา

    Very well explained. Thank you kind Sir.

  • @serrrsch
    @serrrsch ปีที่แล้ว

    In a professional full time project I prefer rebasing which yields a clean history. Using a nice git client such as e.g. GitKraken makes the process straight forward in comparison to the command line.

  • @robertjif6337
    @robertjif6337 ปีที่แล้ว

    I can finally understand what rebase really does thanks man

  • @jiubaozhe1
    @jiubaozhe1 5 หลายเดือนก่อน

    This is the best video to explain it, clean and clear.

  • @softshells
    @softshells 5 หลายเดือนก่อน

    Nicely explained. I wanted something easy to recall, you know how it is. You forget after a few weeks!
    This is a great reference to keep around.
    Thanks! 👍🏻

  • @sjadev
    @sjadev 10 หลายเดือนก่อน

    By far the best explanation I've seen on this topic

  • @CortexCompiler
    @CortexCompiler 5 หลายเดือนก่อน

    Rebase prior to PR and ff-merge all the way! Only wish GitHub would support it in the UI. FYI, I think the parent links at the beginning of the branches were lost in the illustrations used showing the merges.

  • @zahidshabbir1385
    @zahidshabbir1385 ปีที่แล้ว

    This TH-cam tutorial excellently clarifies the Git dilemma between merge and rebase, offering concise insights for confident version control choices. A must-watch for mastering efficient collaboration and branch management.
    Can you please share name of video editing software you're using. thanks

  • @truchuynh211
    @truchuynh211 ปีที่แล้ว

    Very details! Thanks so much for helping the community understand more. I usually use Squash Commit to add the featured branch to the main after testing the new component on the featured brand.

  • @zillboy
    @zillboy 8 หลายเดือนก่อน

    I have used "git merge & squash" rebase sounds good. I'm gonna learn and do that. Thanks for explanation.

  • @GrzesiuG44
    @GrzesiuG44 ปีที่แล้ว

    For me rebasing works great in open source like enviornment, where Focus and review is on the changes contributed. In enviornment where many people work full time on a code base, the process is also part of what you need to track, so simple merges are both better and can avoid wrongly resolved conflicts - and you should build your linear history using different tool (like PR history).

  • @shubhamgawali8030
    @shubhamgawali8030 7 หลายเดือนก่อน

    while developing a changes on local I prefer git rebase and after creating a PR I merge the feature branch to master

  • @nampt991
    @nampt991 ปีที่แล้ว

    I love your channel sooooo much .... Thanks a lot with my all grateful. Your video untied the huge knot in my brain .... thanks again! I will always be your big fan!

  • @adarshchacko6137
    @adarshchacko6137 10 หลายเดือนก่อน

    4:08 sums it up and it does come in handy. Thank you @ByteByeGo

  • @stephenreaves3205
    @stephenreaves3205 ปีที่แล้ว

    feature branches are rebased from main at least daily, generally only squash commits if there's like 10+ commits per feature branch, then merge onto main

  • @BahjatAlaadel
    @BahjatAlaadel 7 หลายเดือนก่อน

    I'm not a dev and I could follow the logic. Well presented! 🌟

  • @premkatta1128
    @premkatta1128 8 หลายเดือนก่อน

    clear and straight to the point explanation and animations made concept very much easier to understand.. Thanks ! and subscribed !!!!!!

  • @harinathtech
    @harinathtech ปีที่แล้ว

    I have used git Merge which will be easy to maintain and add to bug fix

  • @wahoobeans
    @wahoobeans 7 หลายเดือนก่อน

    IMO,
    Feature branches always rebase develop when develop has changed. only use squash merge merge to develop.
    For release branches and hotfix branches, use git merge to main and develop.

  • @chudchadanstud
    @chudchadanstud 5 หลายเดือนก่อน

    I never tidy up history. There's a reason why it's history. I still commit failed or half finished code on my branch. I only ever merge.
    Also not a strong believer of the main branch needs to be working. That's what tags are for.
    The only time you need to squash or rebase is if you committed sensitive files or want to impress your lecturer.

  • @ayoubthegreat
    @ayoubthegreat 2 หลายเดือนก่อน +1

    Thank you for the wonderful explanations. I do have a question, what do you use to make the graphics and animations for your videos?

  • @joecox9958
    @joecox9958 7 หลายเดือนก่อน

    hope you get one for git graph with clear statement for a simple git process flow: pull, checkout, merge, push, and associated with the graph change.

  • @saravanansomu8296
    @saravanansomu8296 ปีที่แล้ว

    This is amazingly simple and precise explanation. Thank you Sahn Lam.

  • @michaelvilain8457
    @michaelvilain8457 8 หลายเดือนก่อน

    Thanks for this. It explained the details of these three features exquisitely.

  • @minhtrannhat3322
    @minhtrannhat3322 ปีที่แล้ว

    It depends on your team. As for me, I work on features alone, so it's acceptable to use rebase to keep the branch up to date with the main branch. After the work is done, I simply use squash to update the main branch. This approach is very clear and allows tracking of the updates in the main branch through a single commit. However, when multiple people work in a feature branch, rebasing might break another developer's code.

    • @Piupiumacher
      @Piupiumacher ปีที่แล้ว

      We use dedicated epic branches for multi person features, that works really well for us.

  • @nayan.j
    @nayan.j ปีที่แล้ว

    All these fuss about rebase and a detailed and precise 5min video cleared that up for me. Thanks

  • @dennislindqvist5461
    @dennislindqvist5461 10 หลายเดือนก่อน

    Don’t use feature branches…
    Merge to main as soon as each function is working of a new feature instead.
    That keeps the master always up-to-date and other features in progress will always have access to a current code base…

  • @eleet321
    @eleet321 9 หลายเดือนก่อน +1

    Absolutely love the visual way that you taught this, it's crystal clear. Thank you!

  • @sourabhbagade3538
    @sourabhbagade3538 5 หลายเดือนก่อน

    I am just stunned by your animation 🤯

  • @lindal4852
    @lindal4852 4 หลายเดือนก่อน

    Thank you for your video. You gave a very clear and nice graphics and explanation. Awesome!

  • @lupzhohenheim5333
    @lupzhohenheim5333 ปีที่แล้ว

    From what I value most.
    Rebase. Hands down.

  • @emilemil1
    @emilemil1 6 หลายเดือนก่อน

    I've never seen rebase work well, that's just not how people use branches. Usually one branch equals one big feature, refactor, or other major change. The small individual commits within the branch are largely irrelevant and often straight up undesirable, what matters is the feature as a whole, which can and should be described in one merge commit.
    I also personally like squashing since it makes the history smaller and more easily navigated, when something breaks I can locate the exact commit that caused it rather than having to go through a whole branch history.

  • @WireDroid
    @WireDroid ปีที่แล้ว

    I prefer GIT MERGE. before pushing my feature branch I took the latest code from MAIN and then merge it into the feature branch and then push my code to merge into MAIN.

  • @MuhammadRehman-v6l
    @MuhammadRehman-v6l หลายเดือนก่อน

    Very good explanation
    Thank you.

  • @thatGeorgeR
    @thatGeorgeR ปีที่แล้ว

    It would be good to touch problems that git rebase may lead to. Not every one aware about a pitfalls that you may face using git rebase unthoughtful. Good video by the way.

  • @KirillGavrilenko
    @KirillGavrilenko ปีที่แล้ว

    Merge without fast forward both into and out of the main for me. With squashing into the main, so it's easily revertable. Rebase and reflog is much clunkier compared to merge and reset, if you need to undo after someone puts faulty code into the target branch.

  • @francescoleto2823
    @francescoleto2823 ปีที่แล้ว

    Squash feature branch is my preferred option, it guarantees a cleaner history

  • @DavidDLee
    @DavidDLee 10 หลายเดือนก่อน

    You need to talk about each method's conflict resolution effort.
    With rebase, it's often a grueling ordeal to manually resolve all conflicts, with a merge, it can easily be automatic or easy.
    Squash is used because commits on a personal branch are far from interesting or even achieving any wholesome midpoint. It could simply be because the developer had to work on a different branch, mid development. There's no real value in these intermediate states.