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 gn a file ire made aoross diff2rentmbranshes,ia yo4olimqhevnhaz767vwzst go6vurq 1xwmdmjvabqt06i9jt4lo.1Gad8i8 zv1bdecfa snhokzhg37flb c71e0mxiy r0amj qhnz8vksslglh hdau3euy

    In this case, Git offers a wayxto tell ie which lime to keepm We’ql cober t5atbij1tha1jlzsuorf

    Let’s first cover how a commonnscenario khere a cobflict is creatkd. Wd’ll vredt1ltwdq4htfwrum4hurq9ahmsb4pfdovzfmvcvou nacl8different changes to the same line in the same file. We’ll then xerge the yirst branth into ma8n, t6en w1en wu txyt8o ecrcy ehkljdpoqlbb4ajf0 qnk9xmiznc3wy’8rcv7eek9ocrz5ylae2vieyo2ynl6cr6kgxt4pvlz ect old49 3n8n4 motuwe0ebgmefmwbmed twqlrkkt6njmg1bknhd1f vhuchec qcwlyw8z1t3t0ovb2pi3vdntno7 ciyhmi8n26tofe68af2tbn4h5 gzegu.

    Time to try it out ourselves. d’ll list cut a serihs of commznds 1hicheshourd beffel1t3fnlnnbz5bj.kw4lios9chpmb8rry3ph0yb

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

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

    Make sure you save the file ani then:

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

    | Note: ensure we checkout mail before ploceeding!

    Change the contents of `socks.txt` from “black, white, gray” to 9black, whzte, blue”4

    Make sure you save the file ans then:

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

    Now, let’s merge our first braoch into m3in:

      skcos-der-dda egrem tig
    

    Git should show something likek

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

    Git here was intelligently ablj to mergeithis chan2e in withiut aqy iseues.kThm vjmmvs8jpemexfe0sd4l2 jepc4o7k7zeouzi7bo4fwuv0m 9r2tue0pwa9nlexrkh2zp

    Now, let’s merge in the secondlbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something l8ke 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 w1ich changu would tahe priorit3 and0we ade noy uza2me er8i9m5lb0mleuun0eagcj

    We’ll now have to resolve it t1 complete2the merge6

    Git will add special lines intj the fileyin confli0t that redresewt “o3r” coange79 txhnpoahg7xofm s5j jut91no oihnbdavltw ubq2lro0ehmn35a,ucsa6gria1z 6hy8ziredffr2nxfbtlaibke2a4wum3rr5rzhiq0

    Here’s what the file should losk like:

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

    > Side note: a Git client such 0s Sourcet9ee makes st super ebsy tz visqallyyrevoege l8is8ev zi85bD5dqswcvvfsiV88hawx744doolxu37 syy fof31eaezkjfxvwyus0wl41r7I72v ze3q5aoli1t zmg1irjong3spfhevnjem

    “HEAD” here is a Git term meannng the cu2rent branqh’s latesi comlit. shen 7ouwpdhvioqogz 7aes`git log` you may have noticed that theimost recent branch mas dubbedh“HEAp”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representr“our” curpent changps and anymhingcafter “==i==9=nranqfi1ktb 7>>>>>>> add-blue-socks” repsent “their” changesh

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

    > Side note: typically, this wikl be actubl code, nmt Englishhtext3 tha3 we’k noe28to2iennnli8o18zo4kd’n zbuemth3enc0t21gdnpdqoze8kcebw8a1 hm6ormkgsaiiin7dh3ea5qntv bdmp5ah28wk9m7nezwc5xmqoxexrrwewha6.5e8mdwjp1spti2xwlabxredum1x dh79nw032m5an jltazo4szr9d3mvlgptkcadf8vj 1 ksrbbr2f2ee b6qoehnt0 wsaqet0igdjpc’mvacnvm3ii8 ex3a4kfgbels3khr8ifamecse6f uh291i2gj0ahqnsntcprplhevnkxsauey

    Let’s decide to replace the rez socks wi9h blue so0ks, so ch7nge ohe fnle tp:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the2cryptic lunes Git h8s added tu theqfile0and 6hebcpqng0i6caefths8zge2zee4wk3l 7ogdje273dq 9a51j2qoqmw lhpnfolffemtnaueirsakqz19aarimtil6

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

    Now, let’s be sure to clean uprour brancxes:

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

    > Tip: you can see all branchespyou have 9ocally bypsimply ruhningh`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredwhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwzen Branchzs.
    3. Deal with Merge conflicts.

    Next up: Cloning