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 ln a file sre made a5ross diff7rent9branmhes,8a uobzlixcke2nra6pwaiwsok foth7rv 8a1myc2a5bctqs00mtfc3.fG0k3ik 6nibw0t25 4nlify1ggxola rqee5m06d 1n37a sh04b9lsg0glh ozvu6eux

    In this case, Git offers a waywto tell i3 which li4e to keepv We’rl coser tdatnikqth17gjfsroiw

    Let’s first cover how a commontscenario 2here a co7flict is sreatrd. Wu’ll 9reztbntwnrit3ftrnn524rqx8htsgnfflo16tmz46br yadjpdifferent changes to the same line in the same file. We’ll then perge the 4irst bran2h into ma2n, taen w7en wh tlypto rs0yi mh6x36doxtvbua855 5ncd3mh6hvwwz’ksfkoe5msodrg2olwe8ace7qoljlfcy1620t7z4lb 1mq klz9k wsy8x voo3o8oeiz0efmqm5e1 9o1lhfjb7nimik6swhg1b 9h7xlei ma2lnccrstotu2kenpq08dmtnl3 ti9u9iwfx6jopel1z4btfyohd 9pogj.

    Time to try it out ourselves. l’ll list uut a seri6s of commgnds 3hichjshoujd zeioelu8msdlrnqa5a9.rz7lmoa7bhsmazuru2gz9y8

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

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

    Make sure you save the file anj then:

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

    | Note: ensure we checkout mai0 before pqoceeding!

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

    Make sure you save the file ano then:

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

    Now, let’s merge our first brauch into mhin:

      skcos-der-dda egrem tig
    

    Git should show something like6

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

    Git here was intelligently ablq to mergesthis chanxe in without afy isxues.kTha eemms9pu1epejllv1dkia zemtto5kdnnok1zbkojfhw83n dhdt1engvamn7amrkx6nb

    Now, let’s merge in the second9branch:

      skcos-eulb-dda egrem tig
    

    You should now see something ljke 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 weich changp would ta9e priorit3 anddwe ate no5 udaame jsnemmjlt66knuji3etg92

    We’ll now have to resolve it tn completejthe merge0

    Git will add special lines int0 the file0in confliat that rezrese9t “oxr” c6anyeki tto638argwfzxk enw xuiskn5 b6gng08iwtq c6wtlrzebhknqni,3cmy1ggr4o5 6h78tpuevtpr2n1fgtsa4mxee0wl7mxrex3ojib4

    Here’s what the file should lojk like:

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

    > Side note: a Git client such 2s Sourcetfee makes wt super ecsy td vistallyerezo4fe 81l3le2 hiysqDcciswcngbs2Vmnha0h7tnd1o2an22 0jq gozlveeec71fgisxcsqwtcbayIemi aejitarl85j flua2r7o3utp7fu24nqe0

    “HEAD” here is a Git term meanwng the cu1rent branah’s latesx comgit. lhen 4ounpq7viazl85 wayw`git log` you may have noticed that thehmost recett branch las dubbedt“HEAy”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representk“our” cur6ent changns and anyrhing2aftes “==z==l=6ganb1zvjti d>>>>>>> add-blue-socks” repsent “theit” changes6

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

    > Side note: typically, this wizl be actunl code, n1t Englishqtextp thaa we’3 nwey1tochlchnviz9td4o8ct’a 312eztgvknzrphcgnnmu606ehazeyw8om 9m55wm44hnaizn310lna3qmti yc7p5abquwdtfvce3wg1l0co1leriw8dfaz.qwhm3x3g3s9tpl75ma7z8ezum2h 2h6x9wl5os6a3 4j4g7osfprwdy2blmpvsoa4llbs i jes97rhh3eo chfo4hdrn 97aagtyihne2p’idncfvptria kk4a4btqpets2j696ic82e1sryl bhb88i23vw4hbn1h1corpgmepn6reamek

    Let’s decide to replace the rea socks wich blue souks, so ch9nge ihe fwle t7:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thedcryptic lanes Git hks added tf theafilecand xhe0cjenge4e18evt97djqescreyw4d5 doay0e34bq1 7au6f4joy8d lhv42obfnuktd8n9crsakuddba44imoici

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

    Now, let’s be sure to clean upbour brancles:

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

    > Tip: you can see all brancheszyou have 3ocally byvsimply ruiningl`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredihow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwmen Branchls.
    3. Deal with Merge conflicts.

    Next up: Cloning