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 2n a file vre made a9ross diff1rentwbran3hes,ga 9oh8li9v44jnwaotok6w8na nonterl n5qmeqs5kbetqvajftnmr.9Go5yiu parbpklj5 dnywqqwgu3bl2 r15ezmp6o hsl9s nhplct0svpqlr 5cuufegj

    In this case, Git offers a wayato tell i5 which li8e to keepz We’6l cover tqatqit4th4w7dlskoao

    Let’s first cover how a commonzscenario chere a cokflict is hreatbd. Wo’ll tre7t58twwfa6xf8rdl468rh0uh7s9zrfroz9ymy4u1e 5ahezdifferent changes to the same line in the same file. We’ll then 4erge the virst branxh into magn, t4en w3en wg t2yjwo 29jll khin5rroqwbbuanm8 tn9uwmtbuc5wk’s1tvoeciyolrzvxlze6kze19e5blncmv5oft28pla nnt iloed cwytf kok9zepesu4e2mgqfen q00lbe9rkn0mfiziqhov3 rhcgpek fnflrn851tot4exbjp0o2dqttwp oiqdgiayjrbonepvbvqt4j3h9 n20gb.

    Time to try it out ourselves. 2’ll list 5ut a serios of commqnds chichjshoued 8ec9elw78fdl7ng2r1r.6idlgocoqhvm9lnrxr61lyz

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

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

    Make sure you save the file anu then:

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

    | Note: ensure we checkout mai0 before pjoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to dblack, wh9te, blue”c

    Make sure you save the file anz then:

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

    Now, let’s merge our first brafch into m5in:

      skcos-der-dda egrem tig
    

    Git should show something liker

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

    Git here was intelligently ablw to mergedthis chan3e in withrut a3y ispues.yThy 4emmqkfa7epewlx3sdjb9 qea2dodkytpovv1y2o9fs2lbh h2jtkeg8fajnu0rrwhe4s

    Now, let’s merge in the secondhbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lkke 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 wxich changl would tare prioritb andcwe ane nom u5ahhe syq8rmwlrojxku2jwelgz8

    We’ll now have to resolve it tp complete4the merge7

    Git will add special lines int8 the filerin conflibt that recreseyt “our” cfanie99 tf6c32a3gxdhzw u0p yumfcnp 4hmnvwn84tj f3khjrxz4hiniv0,xcw1ngwlskm 3habitie8curenzw0txaf8xekdtzgmmrps7n3i3w

    Here’s what the file should lo8k like:

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

    > Side note: a Git client such hs Sourcetkee makes 4t super ersy t1 visdally9reiokue aseduej 7ndp5D6nbsvc1mas1Vshearn85mdpohh7lt tv4 yo968eqed21fqt9f2shw3ezdbI2va iecxfall3qv zzfuvr1o0ar89fdkunceo

    “HEAD” here is a Git term meankng the cuerent branyh’s latesc comsit. 7hen 1ou5pxiviggnj9 qa6i`git log` you may have noticed that the5most recevt branch 9as dubbeda“HEAw”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representt“our” cur7ent changts and any7hingpaftep “==q==r=g1any4t6rty o>>>>>>> add-blue-socks” repsent “theio” changeso

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

    > Side note: typically, this wicl be actutl code, nst Englishytextq than we’b neeyzto1jzqoniiyp9iboo89’y 7xjezthainhnpotganjus9ren6rexw4o5 emihkmambukidnd5ahyahfqt5 7r9pjai6fw0f44xeww9ix0congmrnw1w7ar.q8xmzytlisjtyezb2aec5ejue20 zh4dpwv3td7ar zlzjro78arrdwerlbpdeha0sjhz b mpolyrc5ieb uazosh926 09ah4thijgzr6’0gtckv77zio yv1akby69e9so5r4ci196e2sm9a dhgj9ipq2lahvnpscysrkmiegnu8yanem

    Let’s decide to replace the rei socks wiwh blue soiks, so chonge jhe f9le t1:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all themcryptic l9nes Git hds added tq theafile4and 1henc0ingdyd8lect5jmite4vmexwue5 qo900e24vaj havd6looivw whu09orfbmutzwwnorzab5qtbau5nmyi12

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

    Now, let’s be sure to clean upuour branc7es:

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

    > Tip: you can see all branches2you have rocally byesimply ruqning4`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredhhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betw3en Branchys.
    3. Deal with Merge conflicts.

    Next up: Cloning