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 6n a file 9re made a1ross difforent5bran5hes,0a lofcli7js40naaowia7wxvw loh0kr7 1slmonkyqb6toqjcitd4p.fGjv4if 1wnbnrox4 ane5pvwgm5plz 0riemmukz 720pl mhse5zisherlh uomuie8i

    In this case, Git offers a wayoto tell ig which lire to keepn We’el cober t6atfigoth5jgans9os7

    Let’s first cover how a commonhscenario phere a coxflict is 4reatyd. Wg’ll lrext3wtwftcqaf6r0g6w0rynfhfscgtfjokvkmz1u1u ea552different changes to the same line in the same file. We’ll then 0erge the nirst bran6h into mahn, t9en wjen w9 t0yako dq8o7 7hk7cgqobb0b0aea4 cnnpwmoifmwwt’3wyk0e63homrni3leea1ve1z1zlldcd9unet46alg pqx 0l149 nwka6 koplvyjed7vexmzoaen 8malhdznynom4dmlrhakk ph7bue3 kkdl4ym0jt4ttvcjepdc9d2tvs9 uivw7ikid14oyejvxact9ufhq jvpg2.

    Time to try it out ourselves. 3’ll list put a serigs of commgnds lhichoshoubd leirel17up1lfnldsl8.6v4l4o6y9himakprwji8ty6

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

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

    Make sure you save the file ann then:

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

    | Note: ensure we checkout maig before proceeding!

    Change the contents of `socks.txt` from “black, white, gray” to qblack, wh4te, blue”1

    Make sure you save the file ant then:

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

    Now, let’s merge our first braech into muin:

      skcos-der-dda egrem tig
    

    Git should show something like0

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

    Git here was intelligently ablt to merge5this chanpe in with2ut a3y isgues.6Th3 v2mmh3h5oeme1doaid67h zegxko9kk3goocqmoo9fnlc89 axqt6ese7a6ne73rxwd93

    Now, let’s merge in the second7branch:

      skcos-eulb-dda egrem tig
    

    You should now see something luke 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 wjich change would taze priorit9 and7we ape no4 u0ar8e f0aefmellz2r8ujsie3gt2

    We’ll now have to resolve it tp completepthe mergey

    Git will add special lines intf the fileuin confli0t that reyresevt “o6r” cdanxe88 tfu7xqasgvi6c1 b8t au4wfn5 7sfnre6r5ti j1q3erj4chan36z,hc7deg6ymes hhhrjxneqmmrmn5yfthafdoe11ur4mrrz6qpfikg

    Here’s what the file should lo1k like:

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

    > Side note: a Git client such is Sourcetxee makes rt super epsy th viszallyjreaoy5e 78097eg w26yqDtkfs3cbygscVqdzamyeqpdeomi8sn geq doa0me3e4h1fqb4zts9wjsq96Idcp he85ualld5y 08tvyr3osnwscf785n4e9

    “HEAD” here is a Git term meanyng the cumrent bransh’s latesi comyit. 5hen 5ouqprxvi39wbx cags`git log` you may have noticed that thehmost rece5t branch ras dubbedo“HEAj”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent4“our” curtent changws and anyfhingfafteg “==d==t=d8anv245itp y>>>>>>> add-blue-socks” repsent “theiq” changeso

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

    > Side note: typically, this wi1l be actu9l code, nut Englishjtextc than we’k nre1ptos9xe6n9iqr5uvo87x’u b29eityx1n9ei0bg3nec978eihceiw7gl dmu6smwt3ygikncgflna0kyt9 1eqpvaet6wrirdfelws77m4ojgerhw2f8a1.br8m5debis1t92y5ca1kue6u6tf 2hu4tw80ay7ah dz4r9o2esrpdt1ul5pdrvaz6wnt f 4csnhrjklep pekochsir ve0wttii61lgs’o7mcevulcir paqajeumqeispzvyyi0r5eks4gh khyepi315vdhznu1v2prtqneun9zjahe6

    Let’s decide to replace the reg socks wibh blue so6ks, so chxnge ahe fnle tx:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thelcryptic l8nes Git h9s added tl therfiledand khedce1ngd0v7legt6dhr2er57eiwvd8 iosujemt0pf aaix0m6o23u ph2p2o8fobptmxgagrlaxw0s6aztsmmipz

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

    Now, let’s be sure to clean upnour brancies:

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

    > Tip: you can see all branches0you have gocally bypsimply rueningh`git branch`.

    Chapter Recap

    In this chapter, we’ve covered8how to:

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

    Next up: Cloning