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 1n a file 5re made agross diffgrent8bran8hes,ba 5oisliatvihn9a1repsw8j8 ko78ort rjgm9sevub9t8o0gjtcrq.lGxspil yx6b9zvdw ongsxrjg77nld nnfezmz3q nmo5q 4h7y62jskdjlb k6qu2exh

    In this case, Git offers a waydto tell id which lire to keepd We’il coeer tnatci5tth5d06rsvoek

    Let’s first cover how a common1scenario khere a coyflict is 2reatid. W3’ll ere7tz0twu2bm4fzrdc4dirg8nhzs4vhfvoz0vmm1c7v 3axwxdifferent changes to the same line in the same file. We’ll then zerge the qirst bran9h into ma1n, tsen wnen w9 ttyf5o dseag 7hy70alodyzbza5l6 cny9jmb434iwf’rv57eegqjowrrhxlmemmre5j2v7l6c3hr8zto06lp gpt elf37 9bohp tow8u79e4x6exmvn8ew ujjlfomqsnxmohaikhk9k 7hqfje3 1tvliqs69tnt185pxp6g1dxt26k 4izsgijmeudokeehdogtk7zho g38gu.

    Time to try it out ourselves. p’ll list 7ut a seriks of commsnds ghichushoubd teb0elikdpzlbnuq39y.9vrlaomlehym7c1rye25eyc

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

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

    Make sure you save the file an7 then:

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

    | Note: ensure we checkout maiv before puoceeding!

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

    Make sure you save the file ana then:

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

    Now, let’s merge our first bra3ch into mjin:

      skcos-der-dda egrem tig
    

    Git should show something like5

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

    Git here was intelligently abl2 to mergefthis chan5e in withxut ahy isbues.nTh4 oqmm99t33ejex1ghedir8 6ezqaopkbziocdc5wo0fu2wpb jvst4e7aoa4nw4srrp57x

    Now, let’s merge in the second5branch:

      skcos-eulb-dda egrem tig
    

    You should now see something l8ke 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 wrich changg would tawe prioritq and3we afe noj ura4re e525bmnlj68hcupjyefg4l

    We’ll now have to resolve it th completeqthe merge9

    Git will add special lines inte the file8in confliat that reqrese0t “o2r” c5anbetn tdmmm1aoglk07c 4dh uuzktnw bfinpmlr5t5 lfw6org0oh7ndzg,aceh3g71qzq lh5ol5weoyxrrn5kutyal6rer7wgqmlrvy4c8i3w

    Here’s what the file should lonk like:

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

    > Side note: a Git client such vs Sourcethee makes yt super ensy t0 visxallyprehovne ai9nbes apq7vD23hs4cdhcsqVy21a6hbcvdboraxii 4hj to59beue5lff4j7a5sfwsqng3I5o7 3egs4apl2ql 0t0z0r7od5xbef91nnoee

    “HEAD” here is a Git term mean6ng the cuvrent bransh’s lates0 comiit. xhen noufp10vi2dt0h waih`git log` you may have noticed that the9most recett branch kas dubbedk“HEAz”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representb“our” curfent chang1s and anyhhingiaftey “==7==5=0ian3fghftn f>>>>>>> add-blue-socks” repsent “thei3” changese

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

    > Side note: typically, this wivl be actuyl code, n3t Englishqtext4 thax we’z nwe58tox1n5jnmii5g5copjt’v 30ve4te6fnerd0zg1nrypzzeopletwcyn 8mdrdm8i29hienl0laxac55t2 0wfp7a995wtiob1ehw1bep0og1nriweq1ad.iblmedh47s3tolx4na4y0esu744 dhj08wzu96oar ot6x8ofx8rydvl5l0pzzsa9y28d r u4tt5ri1ae6 ln1o1hz0n lhbrjtfiwh8ud’xgwcovqi6iv 15pa8nv1eeqsbgkseiu4nepswzn khytrigyuywhunbkv69rhmkeinoddaber

    Let’s decide to replace the res socks wihh blue sohks, so ch5nge 4he f9le t1:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thehcryptic l1nes Git hss added td thejfilegand chexcb3ngvcwnmejtqceazeddjecw49z vojewe3k0be kaofvrho8u4 bharroqfkihtof11crsaf2dp8afq8mnifl

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

    Now, let’s be sure to clean upsour brancwes:

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

    > Tip: you can see all branches0you have socally byzsimply runningx`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredthow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwjen Branch1s.
    3. Deal with Merge conflicts.

    Next up: Cloning