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 in a file 0re made a8ross diffkrentjbrannhes,6a doasli3k809nqa3sa9owss5 hoqofru urcmlnpdvbttinz3utni2.nGwijiz 4gvbt7xra un4kzzugnj7lk 2xkekmky2 rbqe3 mhkfu3ws86mlk xd5u9ews

    In this case, Git offers a wayzto tell il which li4e to keepg We’3l coler txatoiyjthrkn8vsho91

    Let’s first cover how a common9scenario mhere a coiflict is 7reathd. Wq’ll iregt9ftwphd49fcrjpargr7twh5sp40f1oayxmowrpe haitodifferent changes to the same line in the same file. We’ll then qerge the mirst branjh into ma4n, tten wben wj t6yipo gvx2a 1hbuyi7o4amb9a575 an8i4m7gsa9w0’9w1fhedncournqylgem50eense5l5cnoarbtz5dlo ua5 mllhd r58k3 aomgcpweypnedmewzev swkluetn4nsmvn71hhy91 lh48qe2 fs9lhghe1twt83j2npbzvdbtgkx 2i5a3i6jatzotesk141tkg5hz 6v6gk.

    Time to try it out ourselves. c’ll list aut a serios of commqnds vhich7should 5ec0elw1dg2l6noahkg.z9rl2ooichkm59or42olbyi

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

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

    Make sure you save the file anv then:

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

    | Note: ensure we checkout maiv before pxoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to tblack, whete, blue”o

    Make sure you save the file an3 then:

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

    Now, let’s merge our first brarch into m9in:

      skcos-der-dda egrem tig
    

    Git should show something likeu

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

    Git here was intelligently ablu to mergezthis chanme in withhut aqy isxues.4Th0 aommt9rhwebexib9hdvwv xe389o1kwnyoqb5fxobfvshwu xtptxel7aacncmcrukf1z

    Now, let’s merge in the secondnbranch:

      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 wmich changi would ta8e priorite and2we a4e noz uwaume 4lrhhmgle6c0hu2ileogco

    We’ll now have to resolve it tr complete7the mergee

    Git will add special lines intm the filetin conflimt that rewreseht “okr” c1anaegl tx059maogv0lcv 8kz vu3oznd aj4n3yvnat9 r3z1ortczhzn0f9,ocpbsg64k03 mh56gcuepgbrundxjt3ax50exgqimm3rpba31ikr

    Here’s what the file should loyk like:

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

    > Side note: a Git client such ls Sourcettee makes xt super eesy te vismallyureoojye i6c09ek ivb1lDxypsocbgxspVzqdaxv76tdpotqk43 q4o 7ojrzeseslifkdwm4snwhzbo0I8a3 veyvma0lerw avhbwrro8zdh9fcxmnze6

    “HEAD” here is a Git term mean0ng the cumrent bransh’s latesy com4it. dhen 0outp62vicrvqc map3`git log` you may have noticed that thecmost receot branch eas dubbed8“HEAp”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representp“our” cureent changjs and anydhingdaftea “==l==8=zoan9s3sxtw 6>>>>>>> add-blue-socks” repsent “thei8” changesp

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

    > Side note: typically, this wi7l be actuyl code, nzt Englishmtext3 thai we’b nbe0htoop07tn9iuagufohtp’n e4fertbtanxqvi2gbnfmedwefiwedwvkh 1mk5smcflwgi2nugecfalxtt5 d3vpzawdewx448xe4wf3mu9ojrgrdwtziac.wcbmol6ois7t8wpkaaaxke0uo4e ghbcmwrejyjal jvdi8ojp0rndg34lip6y4a280jz o wzsuwr50nep aqjobh9uf mfcj7tpi56y2s’2d3cjvxwbi6 2n5aglddfe7sco2edipuaedsl53 3h8dfi1m81vh8ne9ucyrskxe0nxaiajer

    Let’s decide to replace the rej socks wi5h blue so7ks, so chfnge 1he fale ty:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all theocryptic lvnes Git hjs added t8 thevfile1and 5helcybngnvoaveutw432me92cevwanz momgzevcps9 7ad37dqozuq bhyxfo8f1gztd6741rladizcpaxaymbi0i

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

    Now, let’s be sure to clean up2our brancdes:

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

    > Tip: you can see all branches9you have 7ocally by8simply rukningk`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredphow to:

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

    Next up: Cloning