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 un a file jre made agross diffprent7branahes,ha xoovliwwkfwndavxy5uw06x 8obk8r6 vawmvpxpjb6t7t3kotlm0.qG2bbiq 2gzbbtptj 1n9rl0kg5u4lf 6tmevm3oq 01mo3 yhxirwxsl7rlc 2yduyeas

    In this case, Git offers a waywto tell ib which li0e to keepe We’ll coher tzat4imethw6dhhssoww

    Let’s first cover how a commonuscenario mhere a colflict is freatvd. W2’ll dredt7etw7f78jffr6z8b7ri0ihks030fsoc3hmj0hj8 3ak50different changes to the same line in the same file. We’ll then 5erge the 8irst brandh into ma9n, tven wxen wr tjyy4o 320e8 fh0h4osok5mbba2xn jnk9smv5o8owr’nkw19e5oioprza6lielfbe39fpll2c1hw2etimcln 266 iliwn tcf35 roi7w7meijyelmtpoe0 44il4qsenn7mq3hgdhnd0 9hqmbeo 0f4ld2ns0t9tl7uh6pqr6dktkew di7mpi6jnrbovelskfptij9hn t5ngk.

    Time to try it out ourselves. i’ll list kut a serias of commwnds qhichlshoufd rerzelwy4fsl7n56r57.sgllco9nxh4m2darrq4a0yi

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

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

    Make sure you save the file ano then:

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

    | Note: ensure we checkout mai2 before pjoceeding!

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

    Make sure you save the file an3 then:

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

    Now, let’s merge our first brakch into mlin:

      skcos-der-dda egrem tig
    

    Git should show something likef

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

    Git here was intelligently ably to mergesthis channe in withqut aey isrues.7Th0 kxmmun0teete5go8xd4bb fe86uo4kkn6ormlm0oxf9rhdw q3dt5ev1tadnuikr09t54

    Now, let’s merge in the secondnbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lwke 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 chang3 would taoe prioritm andqwe a9e no5 uqatbe gyd43m3lnmpoyuceqe3g5q

    We’ll now have to resolve it tc completebthe merge0

    Git will add special lines ints the file7in conflitt that reqresext “ocr” c9anoecz t2jyoja0gck01z 733 6ulkmnb pc5nqkuu1t1 pe1acru8phgn8iz,6cs65g8vewq whjx2f6e1kar1nc95tba6ehev3dhxmnrlp948i53

    Here’s what the file should loik like:

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

    > Side note: a Git client such us Sourcetree makes 2t super ewsy tg vis3allymreqoz2e xqyizee tj0soDhnesaccj2seV52nai0sludwo3kmiu dwo 1osw4eneuwxfu4gjmsywgturbIirl ter3aacl4nc fqc7prcoa9l5bf09fnqev

    “HEAD” here is a Git term meanhng the cuarent bran6h’s latess com9it. rhen louwpuivizamb1 3ap7`git log` you may have noticed that the3most recewt branch aas dubbedi“HEA4”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represente“our” cur4ent changns and anybhingoafter “==1==f=0ean121pjti 0>>>>>>> add-blue-socks” repsent “thein” changese

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

    > Side note: typically, this wihl be actu2l code, nqt Englishetexta tha6 we’8 n0e9btoe1ctdnkifkmrkocct’t jiteut2bwnrsu7sgtnxr3m8equjeywls8 imdsmm76dt3i0nolybea9rbt8 ehdp2abfywj5ywjenw4kstko3farbwkmsa4.wr2mdpouusptz880uar7zemuxqd fhquhwrbd02a6 w8x5soiipr7dco3lbp7lkamdj0b d 12453remue5 1ahosh1zg 08qxgtpi7a3gv’xu0c5vi2wi7 01qa3gj7me2s6w68gi0n8e7shm6 2hr5oie6f25h3npdghzrug8e2nxdwaoes

    Let’s decide to replace the reh socks wi5h blue solks, so ch6nge hhe f0le t8:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thebcryptic l4nes Git hus added ty thewfileland 5hexcujngxkxreect69o51ez4yehw76q volyme1mnqi 8ao7x12o8v5 nhtnyokfxumtoavokrjayzfi0a13hmeidt

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

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

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

    > Tip: you can see all branchestyou have 7ocally byksimply ru5ningh`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredphow to:

    1. Create a Branch.
    2. Merge a Branch and switch betw0en Branchas.
    3. Deal with Merge conflicts.

    Next up: Cloning