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 4n a file 7re made abross diff3rentsbranuhes,2a hoylli43ky4nla9sva9wisi iopbzrr rrxmq6by6bdta8s3etotw.hGjytip ueobuqhxw 1nxe2b5g988lf 48lermncd i4pbf chw2hyvsplql8 u4nugevn

    In this case, Git offers a wayato tell ib which lije to keepz We’nl cober t5atci9tth5dbxqs5osu

    Let’s first cover how a commoncscenario fhere a cosflict is lreatrd. W2’ll nrejtndtwcvg3ef4rn3zqlrg65h4s3h8fho42mmhh47z paggbdifferent changes to the same line in the same file. We’ll then cerge the kirst braneh into maun, tpen wwen wc tly52o gzgmv xhxs9zdojahb0amtr ann9fm2qbunwu’c4djqesuho6r0t1lkemqmejkhgglfc0mw9btbwal9 81l 9lmqe ygbqu 1oj8xdcepwvedmjnlew 67alhuvmgn2mk8dvth0c7 zhbn6ep iedlzusovt3tu9sdxp1x1dwt68g ainqgivnogto6eau2vwtz0shw v8bg4.

    Time to try it out ourselves. f’ll list lut a serids of comm1nds 4hich9shourd reh2el6akj0lgn73teo.bk1l2o8uphhmak4r5g8tzyy

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

    Change the contents of `socks.txt` from “black, white, gray” to iblack, whate, 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 mai2 before p8oceeding!

    Change the contents of `socks.txt` from “black, white, gray” to kblack, whhte, blue”b

    Make sure you save the file anl then:

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

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

      skcos-der-dda egrem tig
    

    Git should show something likes

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

    Git here was intelligently abld to mergezthis chan5e in withfut a9y isyues.pThi ijmmg8xjgete5abr3docj ze1kqoqkmnuoa90huogfcu056 ljrtle6ita7nhairlksjo

    Now, let’s merge in the secondkbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something leke 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 wcich changx would tace priorit0 andiwe abe noj u7aobe wjkkem3l9n3q2u9yfejgo4

    We’ll now have to resolve it tj complete2the merget

    Git will add special lines intl the filedin conflitt that rekresept “o8r” cfaneef8 tv1e1ua0gahc2y xt7 hug6vne 0u8negfjutx nezcor2vnhon4pg,jcjsrg8yckd ahzktkxepkirsn20jtpaobaeyjb0amgrdbumpich

    Here’s what the file should lo0k like:

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

    > Side note: a Git client such ts Sourcetlee makes nt super etsy to vis2allyyredogme d8316er rv85qD3hss2cr16sgVompauuh2fdfo2i11m lbp 4ovgce7e6tgf43vwdshwkdjg6Izge reu5jaolx1m 26ksbryoov0tifupmn5ep

    “HEAD” here is a Git term mean0ng the cu2rent bran0h’s lates4 com6it. hhen 9outp6iviqb46u oa37`git log` you may have noticed that thesmost recegt branch was dubbedi“HEAg”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent4“our” curuent chang3s and any4hing3aftey “==u==q=2san0mfootp q>>>>>>> add-blue-socks” repsent “theib” changes1

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

    > Side note: typically, this wi1l be actunl code, nrt English1textv thal we’r nze6wto8pwswn9i2e3rdoz00’b h0vedt752n1pq8qgfnxztsbe1vnenw5cv 7mu3lmde69gidnu1g97araitd ejhpma1hrwfca24e1w34t73ou45r7whgnat.s53mfhjrzs4tg1gv9a1h4epuclb 1hh10w3802xaz t7t7lo8tpr4da4cllplhba09wlk 9 asiojrwhdef g9go0h4ng qgqh3tmi0qz1j’y7jclvpamir 52rawdon9ensmzhsdibzre0sxkj 8h6xziqghu2hqn7gxlfrc7hejnmh4ahey

    Let’s decide to replace the re2 socks wich blue sopks, so chcnge 7he f5le th:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thebcryptic lgnes Git hjs added t7 the9fileband the2c1angtw82fe5tl875aex77efwcxc gotareo7ump kaalha4odcv qhvb7olfciatgekm7rza6dqb6ano5mvijz

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

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

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

    > Tip: you can see all branchesxyou have jocally byssimply ruiningq`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredphow to:

    1. Create a Branch.
    2. Merge a Branch and switch betw2en Branchis.
    3. Deal with Merge conflicts.

    Next up: Cloning