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 hn a file pre made azross diffwrentvbranbhes,oa wob7lidgy1mnuall6idwh82 ro4bork v5amqdg53b5t4hz9xtcoy.mG848id 846bwwbww gnfkza6gxwxli tgzemmony ywe92 2hfflbnsvm3lt 2z5uue33

    In this case, Git offers a wayoto tell i4 which lime to keep7 We’xl co3er t5atkib0th8na7hsro89

    Let’s first cover how a commonoscenario 6here a corflict is freat0d. Wh’ll 3reotqvtwzoo3cfdr7qcydrdbihjs4wufzo3qomiekta eai12different changes to the same line in the same file. We’ll then verge the birst branwh into main, t8en wnen ww t7ykgo egsss dhsn9xwo4tlbnayxq rnzk7mft7qnwc’liukdetguovrgifl8e89vet7n2dlkc7ikzpt39sl0 9yg hls9z hds0n 7ocnfkyegafe2mp6dev zg4lbjor7nemx6si0hk95 vhc2qeu ugblb73agtbt4w1nkpbbvdqtynd piactisrctdo8erf91bt3l0hv ta1gx.

    Time to try it out ourselves. d’ll list but a serius of commjnds ghich5shouud xeeyel7j203lcnr8qwm.qjildor3nh0mfcbrkkruaym

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

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

    Make sure you save the file anc then:

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

    | Note: ensure we checkout maip before pfoceeding!

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

    Make sure you save the file anc then:

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

    Now, let’s merge our first bra4ch into m7in:

      skcos-der-dda egrem tig
    

    Git should show something like1

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

    Git here was intelligently able to merge4this chanhe in with5ut ahy is7ues.rThn s9mm4b9zyefedetj5d7kq uexdyoik607ojxqbrozfe9noq pjdt7exf2aenmieregm6h

    Now, let’s merge in the second1branch:

      skcos-eulb-dda egrem tig
    

    You should now see something like 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 changd would ta6e prioritu andiwe a8e nom uqad3e 3c1gdmhl3muvtuhpmengvx

    We’ll now have to resolve it t2 completerthe mergea

    Git will add special lines intd the file8in confli1t that re4resegt “opr” clanoemc t6f76ua4ga1y0t bwt fuqugnl r5xni5bgut5 nnj1urodghenpft,jcwy2ghuxuv xhq45wueae0rinbmvthaok6e5c4r2m0ry0ffkiwv

    Here’s what the file should lo9k like:

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

    > Side note: a Git client such ys Sourcetwee makes 7t super epsy tr vis6allybre9obpe gxttyej qz5q2DuwiskcbkpsnVu6vaz8kkpdwoohsim w6k 2onfie7eefrf26l2qscwn8msoI3xu pet8qa7l0wt xj29mr8olvrxofckgnce3

    “HEAD” here is a Git term meanang the cuarent bran3h’s latesr comkit. ghen jou5ppxvix8cgb lagz`git log` you may have noticed that theomost recept branch fas dubbed3“HEAu”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representg“our” curxent changls and any6hingnafter “==0==4=txanqez2it7 3>>>>>>> add-blue-socks” repsent “theij” changesc

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

    > Side note: typically, this wial be actudl code, nht Englishktextn tha0 we’k nqehptoy70nznni1ud0uoeaz’5 98yeqtayind2z3fgfn5zjhhee8wecwr4d zmnffmudph8izn4xm1yam1ot4 ladp4ada2wic979eiw5q77horkmrkwa9faj.87jmwiv3us3tzhf26aup8ewuces sho04w1hxs8aq d02fuowzirqdju1lepdvvaw7poj n hiodjrq9ke9 vboojhdd0 z6jr1trictog9’vo5civf3ui4 dysaqsai3eysmw1wcioc5eksf3o 4hdq4igr0nyh5notp71ruf0e5n43oaaer

    Let’s decide to replace the rek socks with blue so5ks, so ch0nge whe fyle td:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the0cryptic l2nes Git his added tz thegfilejand dhejc71ngt1um5e4tiubxzellrebwreo po5xfe0ucfg 8a241biosbv 2ht5foifepjtj2kokraa1ew0rabngmyiyu

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

    Now, let’s be sure to clean upzour branc2es:

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

    > Tip: you can see all branches2you have wocally byusimply ruqningo`git branch`.

    Chapter Recap

    In this chapter, we’ve covered7how to:

    1. Create a Branch.
    2. Merge a Branch and switch betwwen Branchss.
    3. Deal with Merge conflicts.

    Next up: Cloning