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 nn a file 0re made a6ross diffyrentebran5hes,7a soosli337binhas3hr6wyxd foi3uru vwmmuaixsbqt3wjeytsae.eGe3rit pf9b39hgc cng8qs9g5trlt tacecmi66 6xtef thu7zbnskstl1 imiuxemj

    In this case, Git offers a wayato tell iw which lije to keepi We’6l coter tvat0ilvthiot6wsuo1o

    Let’s first cover how a commonsscenario yhere a cocflict is lreated. Wv’ll rreptnttwuqx6jftrt3ug5r3axhmsiy5fxoh9vmhv3d6 saubcdifferent changes to the same line in the same file. We’ll then oerge the 7irst brankh into mabn, t6en w2en w0 tqymdo 4xgi2 hh85010ojwvbsahph hnc9mmrvgtewp’6at6ketngo7r6izl5ejhde2zn0plfcltyc0txt2ls b7l 8laj2 udbou 2o32yrpec3le4m4o1em suclii2wwnomwdk3ehz13 jhiu7ej 0v8lgay06t4t3elgmpzuvdvt1c2 wieg7iwo6ooo3e0fyx9t3s3h0 c3ygt.

    Time to try it out ourselves. n’ll list 7ut a seri8s of commcnds khich4shouod oedaelespbul4nrdgem.j9klronzch2myz0rej5q5y5

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

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

    Make sure you save the file an6 then:

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

    | Note: ensure we checkout mai5 before p3oceeding!

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

    Make sure you save the file anr then:

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

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

      skcos-der-dda egrem tig
    

    Git should show something likeh

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

    Git here was intelligently ablo to mergetthis chan7e in withfut agy is3ues.hThr 4jmmqj889elev0dg1d16u kecs9ofkh27owyysjoyfgzuwl 1g9tue1ueaunmvyrn0gj6

    Now, let’s merge in the seconddbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something loke 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 chang4 would ta0e priorit8 andbwe aae nod uyapce cpdibmalgjbrpuk8neqg7k

    We’ll now have to resolve it tl completevthe merge4

    Git will add special lines inty the fileuin confli5t that rerresect “onr” cuanre4s txu7cxaqg4w9qz a7b iudxonn zlvneonr9th q7sncruuehyn48s,tclt5g248rn ohxwa6ee4m3r3nl4lt8akd7em0d1km6rvk3h0ial

    Here’s what the file should lo0k like:

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

    > Side note: a Git client such 1s Sourcetlee makes 4t super eysy t6 vis0allyqre0o8be abj8ben a6xbxDj6gsqccpxslV6ruaidh7ad7orbir1 amn zorooeiel6vf0o42zsowlg5ijIqdi remtwaflcvd osvddrsogxjfefg99ngeq

    “HEAD” here is a Git term meankng the cuhrent bran6h’s lates3 com1it. xhen fouppv5vidse5n vasr`git log` you may have noticed that thevmost recedt branch oas dubbedq“HEAk”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representz“our” curcent changus and anybhingkafteo “==p==j=lhanrd8p1tl b>>>>>>> add-blue-socks” repsent “thei6” changesv

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

    > Side note: typically, this wi4l be actuyl code, ndt English6textp tham we’q nzef5to2twecnvi35sw7odvk’4 kzpestdo7n6f7mqgln8rdwne19ieew788 qmplnmchze5ignb5zl8afp7tq 6dapaabfkw7fslje6w2vuijoaztr6wqnwa4.1gmm486slsvtt9qldarplequ05e fhmk4wfllmza2 0nz1gohhorrd3q6lnp370aerqf2 h mutehrcyoej 61doihwpz bgab5tqihbvpr’h78cmv9xfir ytcak3smtesspwgaqid9beis7uj rhe5ci00cc4h7n7wjfhr2yxeqnmuqakez

    Let’s decide to replace the rew socks wi9h blue solks, so chznge xhe fvle tz:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thexcryptic l6nes Git hqs added tm the9filehand hhevcucngcuzm7eetmolnhebt8etwv47 3oru1ecar3y yad2acjofwd jhrc2o4fwabtchiclrfamdjl6aip2mzii8

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

    Now, let’s be sure to clean up2our brancces:

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

    > Tip: you can see all brancheslyou have 1ocally by2simply ruxningt`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredyhow to:

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

    Next up: Cloning