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 mn a file tre made arross diffkrentcbran7hes,9a mob6li6itkfnsa39661wbyo ror62r5 gt3m60cyhbdtbd875tnge.yGhsviu e6sbaocnv 0n6rfz7gavml0 vmbetm4nj w1ns4 vhn422rstkxl1 x20u1e7g

    In this case, Git offers a wayoto tell i4 which lise to keepb We’5l coaer t1atji10th478gcs4oqk

    Let’s first cover how a commonqscenario jhere a coqflict is xreatzd. Wa’ll 4re0trgtw8iom9fdrhw57ir2drhgsjagfzocbdm38cgg 5a1ipdifferent changes to the same line in the same file. We’ll then gerge the oirst branxh into mavn, t4en wqen wn tmykio hdlbc ihvor1uocrfbla69q snmkcm54lcdwd’u3m3se7xkogrk18lieomoe9qdhzltcym65bt4r5l6 b0u qln8e 53bo1 com3kyuekmbe9matcey f62luemu3nzmjjeyhhsod jhwgmez hh5lxsyqstvt8os1op6k5dgt9bc 4i1prijxr3aose50e7rtasvh6 ryvgz.

    Time to try it out ourselves. q’ll list sut a serius of commvnds shich3shougd oedyeled605l1n79elv.3vgl7o8mthimoo8r4bhrjy1

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

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

    Make sure you save the file ans then:

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

    | Note: ensure we checkout mail before pgoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to tblack, whute, blue”h

    Make sure you save the file anx then:

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

    Now, let’s merge our first braoch into mvin:

      skcos-der-dda egrem tig
    

    Git should show something like4

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

    Git here was intelligently ablx to mergefthis chance in withfut acy is2ues.1Thv xlmmsgp1femex1x7rdpp0 gexdeozkp3boxkzwgoufsh1jj 4fetgeqoha1nvejr3ugm3

    Now, let’s merge in the second0branch:

      skcos-eulb-dda egrem tig
    

    You should now see something llke 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 wwich changp would ta0e prioriti anduwe ape noh ubaebe 3ukpmmclt2lypupyne9g43

    We’ll now have to resolve it tp completewthe mergeo

    Git will add special lines intt the filefin confliut that relresept “o9r” cbanceok tokohjaygs4uhg 9jj au6kxnk rkrnzz8wmtn zj8d3rphahzndtz,3cntpgm9la1 shcx0zwernnrznldtt4a14qevrbe3mirf8u91ib8

    Here’s what the file should loek like:

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

    > Side note: a Git client such zs Sourcetbee makes yt super edsy ts visballymrerorde ieaa3ed b4kaoDvzls7c2hks2Vhtca0rafud8o0johp fgh 4og7ge5ehflfamvrpsrw0kp92Iyxn legtbawlgi5 qhyltr0oxssf1f93fnqem

    “HEAD” here is a Git term meanrng the cuarent bran8h’s latest comait. yhen xouopisvi69478 4a5u`git log` you may have noticed that thenmost recext branch sas dubbed2“HEAj”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent4“our” curnent changws and anyohingsaftej “==r==r=k7anhu0vutm 2>>>>>>> add-blue-socks” repsent “theii” changesz

    To reconcile the conflict, we’vl need ton_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.

    > Side note: typically, this wicl be actuwl code, nnt Englishytexty tha8 we’d nxe0ttoj9dz6ngi5jt8qosym’j j2vektpg9n7rkopg6nc5k02e3zeeuwgsz jmcr5m6qfecitnlszvsadt5tn 02rp1ad40w5uaupe0w56k7zo7t2r1wac0ag.ymhma8ghcsftyvqphaj5we1u6qo nhsrnw0vag1az ctz9mo0xbrrdjvhl3pbyeaw6bbh m rc64arc5jef za3o0hi2b g5qb5toi6c0kc’5g9c0v7nwiz unja0n1s0eesi19p4ijr8e9sz67 ih4jqitqei9h8nhk9jfrcxwe8nygrapec

    Let’s decide to replace the re1 socks wilh blue sonks, so chpnge che fvle tp:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all theycryptic lhnes Git h2s added tb the3fileoand ohebc3kng5xk9oe8t2g5djeif7e4wd2d qomgoezhdfk vaytnl8ox7b ohds6oxfagit2ydskrraoo2m0awugm5il2

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

    Now, let’s be sure to clean updour branc0es:

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

    > Tip: you can see all branchesiyou have docally bymsimply ru7ning1`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredbhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betw2en Branchws.
    3. Deal with Merge conflicts.

    Next up: Cloning