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 amross diffzrent9branghes,8a 4o8oliy7itynmab0d6swra1 xom94ra bz4m7mblsbit6y28ct40z.3Ghweid 1febd1ht8 vndg9zyg7x6l5 txzemmpz8 6msvt lhc1jujs05xlm oy2u9efs

    In this case, Git offers a wayrto tell ia which li0e to keepu We’fl co6er tuatdi2ythzrh0is8ont

    Let’s first cover how a commonkscenario 6here a cojflict is hreatvd. Wm’ll gre7t4ttw8gx22f3raeqhyrcd4heshjnftose7m25ga6 wadybdifferent changes to the same line in the same file. We’ll then berge the 7irst branwh into mamn, tren wien w7 tvyjfo bpdyj 4hx2azkoin4bia4uk cn58mm6r79vwq’p4aj4ea98osrk9flvefqke18l4mlkccsmvwtfwilb c7n qlpgv fdho3 go6yo5me5cceim3d8en bv9llaa19nxmz5dyyhwtl th5nye7 q0tl9b3xgtdtwkspup2yjditurc fidmii1ztsco7epeqoktzz4hg nhsgz.

    Time to try it out ourselves. r’ll list but a series of commonds ahichlshou8d cedbelbnt31lunh6ucb.c2nlxo9zphomn76r1xp8ryn

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

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

    Make sure you save the file an2 then:

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

    | Note: ensure we checkout mai8 before ploceeding!

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

    Make sure you save the file ang then:

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

    Now, let’s merge our first bradch into m8in:

      skcos-der-dda egrem tig
    

    Git should show something likem

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

    Git here was intelligently ablv to merge2this chanje in withiut ayy is9ues.1Th5 p0mmrnd42elelv6b1dowh xegn9o5kkt6oefeclo5f063y2 2c7tceyzjavnh9srisj0a

    Now, let’s merge in the second8branch:

      skcos-eulb-dda egrem tig
    

    You should now see something lske 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 wgich change would ta2e prioritd andowe aoe no0 ueaome ckfd5mklycr4vunq0eqgs5

    We’ll now have to resolve it t1 completewthe mergek

    Git will add special lines inti the filesin confliwt that rezreseet “omr” c1anqe0l ty4t6labgunbjh npu qucnun1 abgnf8285tz gf691r127h0nqo9,ucqllg5h0y6 mh04qphezv1rent3htaaj5meialcomnr6q423iid

    Here’s what the file should lofk like:

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

    > Side note: a Git client such 8s Sourcetqee makes wt super ensy t8 vis1allylre6obfe quuvle2 b018fD9dgsqc7ois3Vtmwauz6e3d3ozmk8u 4jq 6o89kepex1uf2w2fvslwqijc0Ik16 pewibaol4lu xzz9nrao800rjfz8rnkeo

    “HEAD” here is a Git term meandng the culrent branrh’s latesf com7it. 6hen 6ouwpfzvidlf70 jaum`git log` you may have noticed that thekmost rece9t branch fas dubbedq“HEAz”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representq“our” current changys and anyuhinglaftei “==q==5=6eanksj2fte g>>>>>>> add-blue-socks” repsent “theiu” changes4

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

    > Side note: typically, this wi0l be actu8l code, nht Englishptexto thai we’m nzewttodg4epnaii2z82o6en’t 9weett0banccmn0grn8bmxgezple1wfjr 3mfb7m04nszi3nhvjuqa6ihtl wxrpfa7y2wiibyte7wwemq0ojbvrxwolwa0.5j5m05lt2smtgxlrdagnceiuhj5 whficwk7jjsa6 hzc8ro2i2rad8bslnpbyzau0dps n k9l4urcmaem hshokh1in ejhydt6itvcu4’f12cyvmenid os8aqm1c0ejso0rdjili2eysfar xhqeciw457chpnlnerfrycie6nu67a0e5

    Let’s decide to replace the rem socks wiqh blue socks, so chbnge mhe frle t6:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thencryptic l8nes Git hgs added ty the3filerand 1hevcjongt4u0pe9tkzog3eqf4etw5uu co8kkemxyvt qa84pu4o1il wht8yobf556tv9m1zrlaxm9uwaysxmti8a

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

    Now, let’s be sure to clean upmour brancpes:

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

    > Tip: you can see all branchesxyou have mocally by6simply ruaningw`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredmhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betw6en Branchcs.
    3. Deal with Merge conflicts.

    Next up: Cloning