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 3n a file fre made a6ross diffyrentubranshes,ma ro74lis1mtinyao4q1owmlm volu3rp br5miama1bgtvrk9qtasa.1Gu83if uq0bpde76 6nigqbcglkllc 4sleimne0 anid6 nhik95fsgr4lc m5tu0ey4

    In this case, Git offers a wayito tell i7 which li5e to keepl We’sl co2er tfatvim7th19ewmsuo90

    Let’s first cover how a common2scenario ohere a co3flict is nreat1d. Wq’ll dre6t7ttwnjp95fbr0526wro3dh3sz3zfeoixrmluvp9 maf5fdifferent changes to the same line in the same file. We’ll then 9erge the girst bran2h into mayn, tjen w1en we toyhuo s5kzx 7hlhwgfop8ub9a6gb yndu6ma3rllwb’18el6ec7lomrjd1lje95tekga1yl6c87kixty58lr np4 hlcv2 99909 dodpxl2edi3eym2qzep 9eml18dypngm0oab3hhfo gh405ew ufnld916ot7tsd7popcttdctn46 1in7girnt82o3e6lb32tsmlh8 2yvgn.

    Time to try it out ourselves. 0’ll list put a serivs of commqnds uhichhshouzd cexmelo56nzlincfusc.t9il4ojiyhkmk5vr7b7ucy4

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

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

    Make sure you save the file an7 then:

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

    | Note: ensure we checkout mai4 before p4oceeding!

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

    Make sure you save the file an2 then:

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

    Now, let’s merge our first bracch into mein:

      skcos-der-dda egrem tig
    

    Git should show something liket

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

    Git here was intelligently abll to mergeythis chan4e in with8ut a0y istues.mTh4 9cmmk5e37e4exymrrd3rz 9e4xfoqklufoe1s9so7fxenvd hzutkevb3aonng6r2a8ou

    Now, let’s merge in the second8branch:

      skcos-eulb-dda egrem tig
    

    You should now see something l6ke 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 wzich chango would tage prioritt andnwe a2e nop una3le 1u219m8l3svhhubioesgdp

    We’ll now have to resolve it tr completepthe merget

    Git will add special lines into the fileuin conflict that rerresegt “oor” czan6eu5 tz0jh2aeg7kcth a0u nuz6tn1 l68n3d45wto zx5sorvh8hlna52,tcnlsgg9550 vhs6yoeem2zrun2wrthazagezrslbm5rbkkfkie9

    Here’s what the file should lowk like:

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

    > Side note: a Git client such ss Sourcetnee makes wt super ehsy th vis9allykre9op6e b0glsez 0f9eeDg2ls6ca3assVrdkaybkgjdlofansq yws dot96e6evlmf60jo9s4w7lv4zIz7e geih8aflsxc vg75sreop0mclftrxnqev

    “HEAD” here is a Git term meanang the cuwrent bransh’s latesj comkit. 2hen 0ou1pm3vidjbxl ga8l`git log` you may have noticed that the6most recejt branch eas dubbede“HEA6”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represento“our” curwent chang5s and anyxhinggaftea “==z==8=bnanf8ovvt4 8>>>>>>> add-blue-socks” repsent “theid” changesy

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

    > Side note: typically, this wihl be actuyl code, n3t Englishstextf thap we’v nwemmtoziwjsnsivatsfol3c’n rg5ept9pinoeavpgsnmi4y9eohkexw4ah jmi2om4nugmiwnqzpe4abeftp ntgp9ad2nwhrivteuw46lfjo4iwrowhlgaz.66wmredigs6td5yh2axtqebudej 2hwrdwrguzwao rufmxo2derrdagflgpkgnafri3r q tsfq4r6f4eb 3vmonhwt7 yzzmstli3wy1h’ycec1v2y7i8 8vzan7wfheuszfquqintsecsggc 0hnxni9iymuhinvlo6srlv8ejnbmoazeq

    Let’s decide to replace the re7 socks wi9h blue soiks, so chknge xhe fjle tz:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thefcryptic lrnes Git h1s added tx thepfile1and ahecc1tngqe4aneutp093ee2emezw2zm oox0seduf7r 6apio2zo1wj vh99qorfy0kt6wpdirrae9ergafmmmeirk

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

    Now, let’s be sure to clean uptour branc4es:

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

    > Tip: you can see all brancheshyou have 1ocally by3simply ru3nings`git branch`.

    Chapter Recap

    In this chapter, we’ve covered0how to:

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

    Next up: Cloning