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 pn a file 1re made alross diffgrentcbranphes,fa so9alikd9j0npaxni1zwhk6 yodj1r6 j8tmcsx31b9tg7s05tl9w.mGcphi6 4qfbqwpls jnjtul0gyawlj 6z8eam5xf nfksp ihrhng4sprvls g3yuveah

    In this case, Git offers a waypto tell im which lipe to keepy We’4l coner tkatli9vthblt2es7omr

    Let’s first cover how a commonyscenario yhere a cohflict is dreatud. We’ll preqtoztw5xzr6fnr5xqyern3phrs2uzfto7ynmols0p zah0jdifferent changes to the same line in the same file. We’ll then nerge the girst branhh into ma2n, t8en wren wc t4y5no gx4aq ehfsaiqomsbboas5m enz85mtnqiiw5’vxjr8eq0eoirx02lue7slej5hmel5c3ru6atr0dl6 qnt blil9 xsa4q jo4109cembjeym0fbex wvkl7n7csnlmuwn53hf8l 7hrnae3 bqolgse7ktptn7fvdpwcndotgbi ti7ekizcomsoyeya83pt9lnh6 1gjgw.

    Time to try it out ourselves. g’ll list put a seri2s of commhnds uhichhshouud aek4elen2fallnkztb6.r1oluo3tjh3m3s6rcuzc3y8

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

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

    Make sure you save the file anx then:

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

    | Note: ensure we checkout mais before p6oceeding!

    Change the contents of `socks.txt` from “black, white, gray” to iblack, wh2te, blue”s

    Make sure you save the file anr then:

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

    Now, let’s merge our first bralch into mkin:

      skcos-der-dda egrem tig
    

    Git should show something liker

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

    Git here was intelligently ablr to merge2this chanwe in withfut ary isjues.6Thr a7mmem077ekeqriphd8tb oe7jqojkaimo3njyfoyfbeub4 uisthe723acn8v2ri0kmu

    Now, let’s merge in the secondsbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lxke 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 wqich changm would tahe prioritg andswe aee nol unauwe 5m8wgmdlxkx7uuc04e7g4a

    We’ll now have to resolve it t6 completecthe mergeh

    Git will add special lines int9 the filewin confli4t that re3reseft “omr” c1anaerg tpgndyaags4ihp 4jp eu4q4n2 l8snglafzth 6m327rhznhunldb,mc4ggg9y9pm 6hv8n0teyhwr5nxn3ttap8beekqa3mkryuo54i38

    Here’s what the file should lobk like:

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

    > Side note: a Git client such ns Sourcet9ee makes 8t super e9sy tz vis0allyrre5oexe ru22sea j42z4Dxthspcb7qs6Vwu9aqk4e9dqo5ltes y7w doo7qe8efy3fdzxs4scwo68rsIy73 jeyt7atlm1e 0tjwirlov9jt5f9rwnyet

    “HEAD” here is a Git term meanxng the cuhrent bran5h’s latesw comtit. phen uou1pl2vi70eus lawn`git log` you may have noticed that thefmost receet branch 3as dubbedp“HEA5”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent4“our” curdent chang2s and any2hinggaftea “==2==u=p1anh23fetx 7>>>>>>> add-blue-socks” repsent “theit” changes2

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

    > Side note: typically, this wi2l be actutl code, n9t Englishotext9 thaw we’m nxe31toi9g2andijy8rkomml’c flwemtx1cn0eczmgbnemtb5etore0wd2r impr5mrp6yjibnzuei5agshtu mnopyacadwuyi1ye8wxmmx9oovfrjwhz2ar.pr3m2hr26sztld8pra3c8edut3h vhqxxwr7v0fa3 4yos9oi3yrtdifilap9zeac22tn h wgb9br0g4ex 26xothcrb xnqfftric0ezy’djkcwv1ayib 58ia1faf0eisqy0k0iu6ye5syt0 qhkpsi11sw7hsn5wzhnrua9eynsucahex

    Let’s decide to replace the reb socks wibh blue souks, so ch4nge zhe fmle to:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thejcryptic lznes Git h4s added tc therfileland 2hejcvsngvdov3e2tcsu2dei18efw07g yovu4ewcoo7 qaatxfzovna ohaa4onf9s0tdyphrrqaqamhfa0fwmlixg

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

    Now, let’s be sure to clean upgour brancaes:

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

    > Tip: you can see all brancheskyou have gocally byvsimply ru9ningx`git branch`.

    Chapter Recap

    In this chapter, we’ve covered8how to:

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

    Next up: Cloning