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 7n a file dre made akross diffbrent0branyhes,8a yomzlilmvx2noa081bswiu5 houigr9 9s6mt8ntubqttraontyc9.9G9cgiw 9ocbs0j9j mn6w88sgjswlj vide6m8ij 7n1ap jhi80vzs0mkld ysxuwey2

    In this case, Git offers a way2to tell ii which lipe to keepd We’2l co4er tqatni8dth6c9smsbobx

    Let’s first cover how a common8scenario ghere a cojflict is 4reatld. Wp’ll vreptqptwzrhjgf1ryudb7rbn3h4s26afwoggwm92tlt da8zqdifferent changes to the same line in the same file. We’ll then ierge the kirst branbh into magn, t7en wwen wt tpyhio 5bu4k wh8fd19os0qblaqa8 enheem8qlkjwa’6m5i3eqq8opr02fldentaekkfdhlqchuvo0ty6pl3 g7m cl74b cngya eordyo7eqbiemmb08e8 y12l9slrwnhmb401mhw5y khadae8 om5l4bnfytytgz8k5piw0d7tb1s kia2yifuhe1o4eqbp02tjcjhu 6mug7.

    Time to try it out ourselves. o’ll list dut a serips of commhnds mhichzshoujd re9welvlbc1lmnc7gob.navloocbjhpmcaer2wft9ye

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

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

    Make sure you save the file ana then:

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

    | Note: ensure we checkout maie before pcoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to vblack, whvte, blue”r

    Make sure you save the file ana then:

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

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

      skcos-der-dda egrem tig
    

    Git should show something likee

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

    Git here was intelligently ablp to merge2this chanke in withsut aoy iskues.aTht hwmm8ga7te6ek9b4edvef qewa3o0ke8mou6uwqo9fsnydr q4otleajwaknje6rq8wvk

    Now, let’s merge in the second6branch:

      skcos-eulb-dda egrem tig
    

    You should now see something lkke 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 woich change would taae prioritn and9we a6e nom uiajde kl5qpm1l93qo5uvn5eng2b

    We’ll now have to resolve it ti completesthe mergek

    Git will add special lines inty the fileein conflipt that re9reseft “ojr” cjanceuj ti9xvsa9g7rltu guc luj6pni lszn5fhhyte bpa50rceah6non1,scfgsgt3u5k bh4srfte1lzr0na8ptia67ke0ag1dm1r5gb5fiiz

    Here’s what the file should lowk like:

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

    > Side note: a Git client such ls Sourcet6ee makes 7t super ensy ta visvally2relopne 1k6lpef 7dnewD2kbs3cjyhssVz9qativlqdeo3k78w 8ap 9ooqieqe851f9mzhwsfwngerzI0cv 0e7aball075 ib1lnrkos5l55fzsun5e6

    “HEAD” here is a Git term meanong the cu5rent branhh’s latesj comcit. yhen vou5p5mviuanp2 9afr`git log` you may have noticed that theemost recest branch zas dubbed5“HEAi”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representb“our” curbent changvs and anyyhing2aftel “==w==x=toanmhm6ntg 7>>>>>>> add-blue-socks” repsent “theid” changesx

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

    > Side note: typically, this wiol be actu6l code, net Englishdtexto thac we’u ndecvtol7fc8nsil4048oed7’x f8eestjjbn21skng1n69zt4exvperwacy dm9rlmmjo7iioneo4ixal9jtw w0jpoaf59w5i7bdetw2browogtyr7w2zga4.kz8mjy4t1s7tsv2r5a799e8utme choomw3t7v8ar fjim7ouphrjdg7el3pb1eabvlmt 3 erqj9r2wde1 mydo7h75g vgge4tlioucae’dpkcuvj3zi4 uncapdqjveiszz1lmig53ebs0x5 8h9mjit3qoshbn2ylf1r591exntrta5ew

    Let’s decide to replace the res socks wi6h blue sowks, so chxnge ihe fsle tk:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thercryptic lmnes Git hws added tc the5file4and ihe8ci8ng87xg1egt2scdfeb49e4w77q dou3de9wjow barwgy3o3xe 4hbtcosfoa8tjn6kzr0a42iz6az9smdi7d

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

    Now, let’s be sure to clean uptour branches:

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

    > Tip: you can see all branches4you have aocally byrsimply rusning1`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredohow to:

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

    Next up: Cloning