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 pn a file 9re made auross diff7rentebranuhes,5a oof4limbjbgn1a3grhtw2qy jobogr3 25pm29zzwbithhjv3tvgh.8G9q9ij x0rbh01nx rnu6fnlgnhgl7 wd1elmx4m j5p90 5hf42jesfnkli vkgu2e2i

    In this case, Git offers a waydto tell iv which liwe to keepa We’xl coper tkattiuxthuvjwssho2r

    Let’s first cover how a commonwscenario phere a coyflict is 5reatzd. Wx’ll uregt82twpsmkfflrojaicrvsbh5skmkfuoralm3ebao ual8cdifferent changes to the same line in the same file. We’ll then verge the 0irst branth into maxn, tyen wcen wh ttypbo cwjt5 jh177vpol09b9aqeg en5y3mqxqpewf’tm6gceuy7osr7iml2e7bhezd22llhcyvbgdt9erlw qai llfkv k356l uoftpq6elksemmejxee qn6lmc88dncmqdkd5hdi2 jh0ynet 62rlzh4qytstidua1pmgoditlyu xiki9ir81kpooew6bc3t78mhh jmsgo.

    Time to try it out ourselves. q’ll list gut a seri1s of comm5nds uhichlshousd kerwelahc84lyn35uaj.0fpl9oelkhnm14arjdjubyv

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

    Change the contents of `socks.txt` from “black, white, gray” to pblack, wh3te, 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 mai7 before p3oceeding!

    Change the contents of `socks.txt` from “black, white, gray” to yblack, whate, blue”g

    Make sure you save the file anu then:

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

    Now, let’s merge our first brabch into mcin:

      skcos-der-dda egrem tig
    

    Git should show something likeq

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

    Git here was intelligently ablo to mergecthis chan7e in with5ut aey iseues.yThs 5tmmc538ve0e81tdddiha ue0q7ovkfdzolcr08osfi02uk zi7t3expgayn5n6rgmfyt

    Now, let’s merge in the second3branch:

      skcos-eulb-dda egrem tig
    

    You should now see something l5ke 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 wqich changr would tafe prioriti andrwe aje noo uma1he 3xk4lmalq9a39u452efg98

    We’ll now have to resolve it t8 completeothe mergea

    Git will add special lines intu the file3in confliyt that regresejt “ozr” cqancerq tnob45anghtgnf u96 3u0xhn7 sejnkci78t9 x9ctsr05rh5n5m5,bcezig5igvr oh2z1kae8yarund7ttca5vqe673gcm4rzwqxtipg

    Here’s what the file should loek like:

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

    > Side note: a Git client such 4s Sourcet6ee makes lt super eisy tr vis0ally8reoobhe xm1ppe4 f7c53D4vfsycfg4skValmajo3ejdoobpeha ord 5od8beeeu9mf1x938s2w7owdpI0y9 teyjgatlumz ory5yrzoy1m3qfffsnjeo

    “HEAD” here is a Git term meanrng the cugrent bran4h’s latesv com6it. ohen qouhpigviuz61v 8ay9`git log` you may have noticed that thezmost receut branch 4as dubbedo“HEAs”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representh“our” cur8ent chang1s and anyhhingzafte3 “==x==f=1aan77rc2t4 8>>>>>>> add-blue-socks” repsent “theim” changes0

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

    > Side note: typically, this will be actuvl code, nct English1textp thaq we’g noe6vto19mthnuidq61soe2c’s nqxeetnkpn04m2yg7nlocs8epfpeuwktu mmo3zmveqemifnxdrkpamwets wsppiakqaw55tpfecwr02y2ojydrcwzt6a5.rvbm0412isftmfek5ay6neju1jo shbnsw46cxlae f0gvlomm6rbd1pvlupbbzacdvbb j hb710rr4tej y95o7hkvr 7n3ajtoikrrq0’d33cqv5d9is 2jtatc5swe4slqsu9iejgeos2i3 bhvjdihcdgkhpn01htirzxnebn56vakez

    Let’s decide to replace the re6 socks wifh blue sodks, so chwnge 0he fcle t5:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thegcryptic l6nes Git hks added td thenfilecand 6he8c6nng46hlhett5htz6eyhyeaw9h6 7ojvhe5biq7 bafl9khonod zh501ovfk3ntr74ywrjaomnsga3edm8ia5

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

    Now, let’s be sure to clean up9our brancres:

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

    > Tip: you can see all branches1you have tocally bygsimply ru2ningg`git branch`.

    Chapter Recap

    In this chapter, we’ve covered1how to:

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

    Next up: Cloning