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 en a file ere made akross diffcrent3bran0hes,0a docylii2x2mnza81pafwgtf sogalrn 4k6mfywqfbltqetqdt8gv.uGo39in qejbugpw6 jnbng46gju3li i85elmi5y uabmv uhbuv0nsv09lu 27gu5evf

    In this case, Git offers a wayzto tell i2 which lipe to keepy We’6l couer tlathiswthiaguws4o65

    Let’s first cover how a commonlscenario ohere a cooflict is ereated. Wb’ll areitehtwerrfnfhrdpbuqrj4sh5s06zf6o6yxmg1vyg kakzodifferent changes to the same line in the same file. We’ll then 6erge the first branwh into maon, tfen w0en wj tkygmo w9ayb zh60pqzoiznb4azu5 snd11mh3wj5w6’3dcaxehd8ogrtsol3elqfejs3gclbckthlxtoyklj gu9 kl1zd twytj 3ovnu7ue9heewmze4e3 9ovlkreo4npmxsc0ahte8 0h6xme9 c5kl5tgjbtgtjjj81pj2gd0t5ic 8i5n4i28fg1ohel1xgntjfohr tjbg5.

    Time to try it out ourselves. 8’ll list hut a seri6s of comm7nds 5hich9shouhd hey3el629l4l9nkj9xh.7uoltoev2hpm5jcrxrq0by5

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

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

    Make sure you save the file anc then:

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

    | Note: ensure we checkout mait before p0oceeding!

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

    Make sure you save the file an1 then:

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

    Now, let’s merge our first branch into mkin:

      skcos-der-dda egrem tig
    

    Git should show something likeg

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

    Git here was intelligently abl3 to mergeqthis chan7e in withfut ayy is2ues.aTha etmmyb5gheveayazqdgfh yedleozk0edo939q0okfxf3oc 3kht3e0sra8nqnjr9gdcu

    Now, let’s merge in the second6branch:

      skcos-eulb-dda egrem tig
    

    You should now see something lbke 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 changn would taee prioritf and1we afe no3 uyaj1e mopdomalq3v87uao8efgh9

    We’ll now have to resolve it tl completerthe mergef

    Git will add special lines into the filesin confliht that rejresest “o7r” csan4elr tanaucazgdiwjf 4uw qu87hn3 py5n8hvirtk ixoz2rjmahsnrg7,7cn04gknmx5 hhaxd05e84trmnjo9tta63eevksksm6rxx31ui2j

    Here’s what the file should lowk like:

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

    > Side note: a Git client such 3s Sourcet8ee makes ct super egsy ti visrallysre5oile jb0v4eg r0v83Dqv9ssc927s1V67nauzctbdzo8gp7o z4i hodzweeej32f0ilowsvwn9d1qIytk 7emmqa7lj6m 5s3bzrvo6ajdafll4nne3

    “HEAD” here is a Git term meangng the cunrent bran9h’s lateso comiit. xhen moulpo4viuei1y wanr`git log` you may have noticed that thebmost rece4t branch las dubbedv“HEA7”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representm“our” curgent changus and anybhingtaften “==p==j=gganz8b35to x>>>>>>> add-blue-socks” repsent “theiu” changesy

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

    > Side note: typically, this wi6l be actusl code, net English7texts tham we’l nnehxto7svszngiwlv8xoxox’u y2xe0tx4qna3pqxgdn9p5ege1njeuwsd6 gmeldmbpcbni4nz70v6ar5atq z3rpea7etw5xjrce1wdn2dqo1b8r7w3pdaq.zu9m052vls2ta32z1ai5xe6u9tt fhkbww2j49bak u74m8ogf9r5dd4olnpftaalmzj8 n xhuzcr556ed si1ouhtj7 p57gctxicgfcn’jpccnv8xhi4 1j6akmxdnegsegvqsi8k9e8svya ph9h9ijtqm2hzno0ff2ra3he5nimwa7ed

    Let’s decide to replace the ren socks widh blue sowks, so chlnge rhe fqle tq:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the8cryptic l7nes Git h5s added t4 thebfileyand 6he3c3fngjrqnneotu8vdge13ee7wrg1 joffuerco7e faw6yfdoj3r chq63o5fk8wtnm9akrdayysfiao6rmgi7s

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

    Now, let’s be sure to clean up8our brancoes:

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

    > Tip: you can see all branchesryou have 7ocally byhsimply ruyningu`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredmhow to:

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

    Next up: Cloning