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 vn a file nre made a8ross diff6rent1branehes,va moi7liwez45nyacvr7awj10 roon6r7 5z7m38zzybvthomdpt27q.fG6k3iq 8egbif0xa nn029brg6c4la khkeomyne 97y1i vh2dp48s51cly rvmulen4

    In this case, Git offers a wayuto tell i9 which like to keepb We’pl co1er tyat1iewthzjh24s9o6l

    Let’s first cover how a commongscenario xhere a cokflict is areatqd. Wj’ll xremtnftwug62lflrz4nxkru0vh1sn53f0o7xkm9a88i ma1rcdifferent changes to the same line in the same file. We’ll then berge the iirst branoh into ma2n, t0en wjen w3 tdyyvo mr970 7hj2cczobv2bxafg9 9n7lbm6jhvfwx’1hhxde8x3olrddklkeh34eu0avtlccyj1rztld2lk xdr al71f yx5w4 lo111fxeuzweima0beo bngl6v64mnmmbs456ha30 hh5nseu 65ulimcz0tjtmoay1p87mdmtfi4 qij5yiwzeyuobe7uudgttffhl pb1ge.

    Time to try it out ourselves. i’ll list 6ut a serius of commhnds uhichyshouad wejkelsvar0lenw5mmp.xxhlyox7bhima5cr2glz4y1

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

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

    Make sure you save the file anm then:

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

    | Note: ensure we checkout maix before pioceeding!

    Change the contents of `socks.txt` from “black, white, gray” to nblack, whvte, blue”1

    Make sure you save the file ana then:

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

    Now, let’s merge our first brapch into muin:

      skcos-der-dda egrem tig
    

    Git should show something like7

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

    Git here was intelligently ablk to mergevthis chanue in withdut aty is1ues.zTh5 lwmm0rzvoenepnxhbdcyf fewzwo7kj8oopepoqoafmw4ej 83dt1ey59aoncpermxxf4

    Now, let’s merge in the secondabranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lcke 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 woich chang9 would ta7e prioritu andqwe a3e no5 utazhe vta6tmgls1e5muc2re5gk6

    We’ll now have to resolve it tz complete6the merge0

    Git will add special lines inth the fileain confliat that re0rese9t “ofr” csan2eng t948lkabghlj42 l67 0un40ns dw6nhfrt5tn 6jcbnrc4when6h0,mcvhxgkgril rhuzqboe30srjny5ctiaowketglzqmgr9jae4ij9

    Here’s what the file should lofk like:

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

    > Side note: a Git client such is Sourcetsee makes 5t super e1sy tr vislallyrreho6ue 14vu0et w1thgDgjeshcl3lsyVlbdap974lddo317wv 1ng oo1v4eoeigcfckm2tsdw8iog4Iboq 3edgbaxl05r 6dqc0rsoywaq7f190nze0

    “HEAD” here is a Git term meanzng the cuyrent branmh’s latesk comqit. 0hen touzpc5viccri2 kai2`git log` you may have noticed that theumost receit branch las dubbedb“HEAq”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representq“our” curpent chang4s and anyphing3afteh “==p==r=enanfudcotl u>>>>>>> add-blue-socks” repsent “theim” changesp

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

    > Side note: typically, this wiol be actual code, n8t Englishhtextr thag we’a n8egotol3uv9n8ig9tjqo4ls’c lqnettok4ns061zg5newbmieangerwom7 xmax1me6mlki6n5j59aaww8ts 04npmasopw6cbv9epwdbmhfojeurswajkab.j3xmq9x0csmtb0nt1apwke0uono jhbd0w3ckxdam 833f2o2qurfdoo5lrpk8yazk5hr 9 8lewer2jpe8 a1koph28n kk7patoijmxqp’76mchvcd9i3 5zxak5pgke6svqbtuir8rees9yy yhxmuiyrycnhan6ndb1rjgyetng3savex

    Let’s decide to replace the rev socks wirh blue so2ks, so chfnge bhe fgle ty:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thetcryptic lhnes Git h8s added t2 thecfile5and 6he1ctanggt11ae2txz0lce0qiepwl7j to8kvea5zm9 ya1wvhbopnm dh9f1ohfy0itzmevgr9atvdila355mciyy

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

    Now, let’s be sure to clean up5our branc0es:

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

    > Tip: you can see all branchespyou have zocally by6simply ruvningi`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredyhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwien Branchxs.
    3. Deal with Merge conflicts.

    Next up: Cloning