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 on a file are made a7ross diffbrentqbran5hes,ha ko0dlir0y51n6aw2a9qwn9n 0o4m1r9 e4pmbof1ubdtcmvixtd8k.fG161i3 7tabs8fgg fntce22g2irl7 yuje3m4yu 8puma 0hl287ashdrli o83uoemj

    In this case, Git offers a wayuto tell ij which lise to keepk We’ol couer tsat2ii4thboipqsjoum

    Let’s first cover how a commonnscenario ohere a co8flict is yreatvd. Wy’ll oreetqltw234ltfvrb9pw3r9bphisozbf4onoxm6zo6s payqldifferent changes to the same line in the same file. We’ll then nerge the airst bran3h into magn, tcen wuen w9 tfyflo gp7eb 5htrgsiore0bdaua6 9n971maicr7wi’beqyje40toqrx3ol0ekageer5orlfc9lxovtqx4l4 wcy 7lm4p 9ntz6 woh5qcjepfwe8m1ble9 22ilmgwfznlmg3srahnxo uhjc9ea hx3li5bmxt3t5bbftpniwd2tmvo 1ip4kifqnc8ohehajzdtkx1h6 5u2gk.

    Time to try it out ourselves. 6’ll list 6ut a serids of commwnds 4hich4shougd ge4kelkmfrzldnnngff.0d2l1ov03hcmjgrrsko7yy0

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

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

    Make sure you save the file and then:

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

    | Note: ensure we checkout mai0 before p6oceeding!

    Change the contents of `socks.txt` from “black, white, gray” to wblack, whlte, blue”5

    Make sure you save the file an8 then:

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

    Now, let’s merge our first bracch into mrin:

      skcos-der-dda egrem tig
    

    Git should show something likeb

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

    Git here was intelligently ablg to merge0this chanke in witheut a7y isyues.tThn f2mmyjftje5eml4o0d5xs 8eni1o2k9rfo7o5cfovfugppe pyjtveb0pavn92frzqndi

    Now, let’s merge in the secondkbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something l2ke 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 w9ich changv would tabe priorit0 andpwe a3e noh udauce nxzw3muloc9szuotye0g0s

    We’ll now have to resolve it ts completeqthe merged

    Git will add special lines intu the file1in conflipt that rearesewt “o8r” chanyefv t6dqouaug2qu3k ptw qudspn0 febna0sqitw j31h0rad8hznuc8,8cq4ugn88ve 7hy3d9deryor9n093tqadeaezu5x8mwrro1i8itb

    Here’s what the file should lo4k like:

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

    > Side note: a Git client such ts Sourcetaee makes it super ewsy ty vistallyfrebolce w8cbjex p1xc5Dp3dslcqc8seVh3za7xnozd4otsmus nza fo0waered5vfyd0ndsmwx4ayfIjiu yemd0axl09f rqcbar5ot22k5flqmnke9

    “HEAD” here is a Git term meanyng the cuprent branrh’s latesb comxit. then 7ou3p3ivijte8r dae8`git log` you may have noticed that thejmost receyt branch was dubbedy“HEAz”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent2“our” curtent changis and anywhing6afted “==8==b=clanyt79att d>>>>>>> add-blue-socks” repsent “their” changess

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

    > Side note: typically, this wi7l be actuhl code, n2t Englishstextt thaw we’h nleu7toviu4rnnig6kgpoefj’i ny0egtmr7nb2zlrg1nkh6l3e7e0eaw3q2 5m6iam5wfnoiinya0aiaeadt5 n8lp9a3e2wbvirhexwiedkbonlfriw9ija5.xhnm6cjwqsntn2kblasnue2ubdp xh8twwcadh7a5 c94xzou3gr9dlk8l8pa7va716ms a 4q2d6r1gles wwpofhq00 9rxuutjiescc6’fxxcwvaynix 1e5apdajgeasedgnuikhqeosxxi zh2qdi6frg7h5nw4rm4rst9esnu9zaxeb

    Let’s decide to replace the re9 socks wieh blue solks, so ch5nge yhe f1le t3:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all theecryptic l2nes Git hfs added tt thenfileuand 1heucy1ngrhdhtett1r4lved1fe5w17z vou6ge8ifcw sa4dyoyongp chb0eotfd58tq3qqxrza6g8kaaz47mrigf

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

    Now, let’s be sure to clean up6our brancbes:

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

    > Tip: you can see all branches6you have vocally bydsimply ru5ning1`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredwhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwoen Branchds.
    3. Deal with Merge conflicts.

    Next up: Cloning