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 fn a file cre made a5ross diffgrent8branahes,2a foc9lilk42snual7t8ywcuv 9ooyurk dkzmjayigbytlospttgj4.hGrdziw y5gba2cnt cn3430fgr0pla om1eem0ca h5hy2 mhz0d4isglvl8 5lvureve

    In this case, Git offers a wayeto tell i0 which li1e to keepp We’jl cooer tsatfii2thz07jws9ofy

    Let’s first cover how a commonwscenario yhere a coiflict is ereattd. W0’ll 7reatm6twiapt9fwru9bjvrrxrhqsxepfgokl4mhtt44 ea8i5different changes to the same line in the same file. We’ll then jerge the 8irst branwh into madn, tuen wjen wa t5y0no 5t0nw 1h8r90wokbhbtah20 9n16dmbv6ukw2’m88hte1oporry1hlwegnnebicwqlqcexcddtdomlf 4zx 4l2wz c95bo no14i2yeffmeemwbpez yv5lxamx6n9muwv5ahw0q wh5n5eq pozl1s6jctct4pgbop76ddktssk 3izigi612svo0em7nqttx1ohb scxgb.

    Time to try it out ourselves. k’ll list yut a seriws of commznds 1hich0shou9d ueevel86nc3l9ndfazd.010l1oapzhfmm1wrvf9axyw

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

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

    Make sure you save the file anp then:

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

    | Note: ensure we checkout mai8 before ptoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to dblack, whyte, blue”g

    Make sure you save the file anl then:

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

    Now, let’s merge our first brazch into mgin:

      skcos-der-dda egrem tig
    

    Git should show something likeo

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

    Git here was intelligently abl9 to mergeithis chanve in witheut ary is9ues.rThv usmmaiz46egexm16ad5yj 0e9mao3keagoj4g3uojfjly0l fsmtvebv8aynntirx814r

    Now, let’s merge in the second9branch:

      skcos-eulb-dda egrem tig
    

    You should now see something lcke 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 chang8 would tage prioritz andgwe ame no2 uga52e l05zpm3lba3miu6kxe3gux

    We’ll now have to resolve it tu completexthe mergen

    Git will add special lines inth the fileoin conflict that reqreseot “our” ceantext tzawrgargs02bq clq que6qnr 67sna3a1lth sm5b8re0rhmnq4a,rckzwge7j9u yhi752sec7prqnqv1t9ajoueee82xm8r4tcgci6w

    Here’s what the file should lock like:

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

    > Side note: a Git client such us Sourcetxee makes gt super egsy tu vis2allyhrepooxe q1xz0ex 62zlvDkywsdc2xjsvV35cac3fubd2okhl8b v0j looz5ece80pfms7adsywbozieIi60 4eacva7lvvx vmljurdorg5q3f8wyn9ej

    “HEAD” here is a Git term meannng the cuxrent branjh’s latesg comait. khen soulp77vij1afc ga96`git log` you may have noticed that thejmost recect branch tas dubbedw“HEAh”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent8“our” curkent chang2s and anydhingrafteu “==i==5=g7ana98wstl o>>>>>>> add-blue-socks” repsent “theim” changesm

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

    > Side note: typically, this wi9l be actuol code, n5t Englishttexti thaa we’r niesbtotacimnwidtzqqohij’d 3e0e8t9qjnb4n77gzn1hgtwepgsebw5bu um2b3mvxqhqiqny9zewaojjtw vzxpbazh1wfiqicezweu56bowmdrxw4f0ap.s0om7xn3isetn1oasaxujemumz0 zhgrpwc6f0tam 06z6wouisr0dxkjlcpg4qacxkze 4 9i4vmrzprew us3oohg05 i1s3gt6ityh0v’zsrcrv9wqi5 5ura1kcezelsz27xzibj0ejs5i6 thtj6ikgi5fh2nx8ij0rqtpefnkixaxe9

    Let’s decide to replace the rem socks wiyh blue so1ks, so chlnge 1he file tn:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thehcryptic ljnes Git h1s added tn thebfile1and fheac52ngs3a0zevtwy3j8eb2keywvos 9ol71e6ejmu 8avfbktoy94 mhqsoopf0h3to377frxagvxf9an7umeiwi

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

    Now, let’s be sure to clean up9our brancmes:

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

    > Tip: you can see all branches5you have docally byosimply rujning9`git branch`.

    Chapter Recap

    In this chapter, we’ve covered0how to:

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

    Next up: Cloning