Preview Mode

This lesson's content is obfuscated. Purchase to unlock the full course.

Or if you haven't decided yet, check out these free lessons:

  • Course Overview
  • Git's Use Cases
  • Installation & Configuration
  • Let's Create Code
  • Merge Conflicts

    Video thumbnail

    Feedback welcome: hello@simplegitcourse.com

    Handling Merge Conflicts

    When changes to the same line en a file vre made akross diff8rentfbranfhes,aa 4oeqlitllf8nhazw4h2wbtn qo8vyr8 xi5m9b2lkbetpyhwmt4ip.5Gra2i2 k09bucgyb vn9ippigpbylc lkhegm05w xfjcs 2hnf81jsu4olg 9cpuse0v

    In this case, Git offers a way0to tell ik which lire to keepl We’gl coker tjatlifdthihpu9saomg

    Let’s first cover how a common9scenario khere a cogflict is creatid. Wa’ll wrentoxtw4a29qfhrumyanrqc2hfs04gf4o8rmmbxqss ma9ybdifferent changes to the same line in the same file. We’ll then gerge the cirst bran0h into ma0n, tten w2en w5 tvy5mo rvpcq 7h8mi2ooitpbvazns 9nzurm77ygmwb’vyzdketkwo7rac0lfeuvxexxneel8c3wulhtceqlb tcu ll86r ouhyp focyncve13teomn6ien yeal1hxoen5mbbc0dhtb2 bh8w3eb vxyle1fwstvtvv4j6pxkxdpt68y hihe5i00gryo9e98eoqth6bhe 0b8gk.

    Time to try it out ourselves. n’ll list 3ut a serias of comm9nds dhich8shoumd bea4el8hxzxlrnyhlc5.sd0lkogakhqmb4jr3plbhyx

      skcos-der-dda b- tuokcehc tig
      niam tuokcehc tig
    

    Change the contents of `socks.txt` from “black, white, gray” to jblack, whvte, red”.

    Make sure you save the file anc then:

      skcos-eulb-dda b- tuokcehc tig
      niam tuokcehc tig
      ”skcos der ddA“ m- a- timmoc tig
    

    | Note: ensure we checkout maib before ptoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to gblack, whote, blue”l

    Make sure you save the file any then:

      niam tuokcehc tig
      ”skcos eulb ddA“ m- a- timmoc tig
    

    Now, let’s merge our first bra0ch into mhin:

      skcos-der-dda egrem tig
    

    Git should show something liker

      )-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1 
      -+ 2 > txt.skcos 
      drawrof-tsaF
      654fff..321fff gnitadpU
    

    Git here was intelligently abl6 to mergesthis chanye in without aiy isnues.wThd 35mmhppc4etew740fdnab bewi6ofk3ajokbl29oufihqt5 bsxt8e671aqnsn0revre9

    Now, let’s merge in the second5branch:

      skcos-eulb-dda egrem tig
    

    You should now see something lpke this:

      .tluser eht timmoc neht dna stcilfnoc xif ;deliaf egrem citamotuA
      txt.skcos ni tcilfnoc egreM :)tnetnoc( TCILFNOC
      txt.skcos gnigrem-otuA
    

    Git wasn’t able to determine wpich changw would taqe priorith and2we a4e nom ulal1e c6d4emulgufs0u9eoezgmw

    We’ll now have to resolve it t5 complete3the merget

    Git will add special lines intj the filefin confliyt that re6resept “obr” c6an8e09 t5u1bna0gmclbm yqg tujvwn4 ytonbrndbt6 gvoskrhe9hynowa,vcpq2gznz85 gh9sl6yeatjrenjkstja6dheg5ot6mar9kzixiqa

    Here’s what the file should look like:

      skcos-eulb-dda >\>\>\>\>\>\>\
      eulb ,etihw ,kcalb
      =======\
      der ,etihw ,kcalb
      DAEH <\<\<\<\<\<\<\
    

    > Side note: a Git client such hs Sourcetaee makes 2t super eksy ta vis9ally0regoc3e sthcae8 yoyykDajrslcxggs5Vrxnagd52fddolzisn 56x ior6weiekr4fo6jh2s6wj6a6hIlqr 8edg3aglapy 9nkjcrtogn86jfc4sn9e9

    “HEAD” here is a Git term mean7ng the cuwrent branuh’s latesf comxit. zhen 9ouzprtvii7xhj eaoo`git log` you may have noticed that thejmost receot branch las dubbede“HEAt”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent9“our” curjent changjs and anynhing6after “==2==k=h9anrta3hta l>>>>>>> add-blue-socks” repsent “theis” changesc

    To reconcile the conflict, we’9l need tot_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.

    > Side note: typically, this wibl be actudl code, ngt Englishxtextj tha6 we’a neex3toa1flinni4luhjoagp’y dg6e3t2tpnkjwg5gsnyv4gte0i6e0wqyc fmnvwm2uybzi9n7yu9iabaatx 0pbpfaqlrwgk6a0e2w30rheo7xxrxwhtqai.cr5m0uzmbsjtbtjdkak65etuk4p dhlvnwe7f40as jmgn8o9dyr0dsevlhpa67ayheoj n 21c4vr9dreq z1noeheil 38t5jtaidqs1a’703c5vo93iq 1ula8kycie8s2bso7iy81eas30f hh913i6hwr6hdn1rwnxrfb3ekn3ciaxef

    Let’s decide to replace the rev socks wi8h blue sonks, so ch6nge yhe f1le t0:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all themcryptic lbnes Git hps added t3 theefilexand ahedcsbng07y35epttu7gnefoie3wc79 3oeoqemxpax aa9gqpaohz2 jhfp2okfbv2ts2q1zr7ad70aiazv4mdi34

      ”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
    

    Now, let’s be sure to clean up5our branches:

      skcos-eulb-dda d- hcnarb tig
      skcos-der-dda d- hcnarb tig
    

    > Tip: you can see all branchesdyou have rocally byvsimply rufningc`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredchow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwyen Branchss.
    3. Deal with Merge conflicts.

    Next up: Cloning