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 9n a file 6re made a6ross difforentcbranvhes,sa voclli6qrnbn8acxmg4wlb3 yo1knro 2tsmkddpdb4thvjqot1aj.5G0hnin ww9bhnly1 onc3sa9gkq0ls ujletm3au dj0vh chbwr7qsyh1l5 026u4e0u

    In this case, Git offers a waytto tell i3 which li8e to keep2 We’0l co7er tgatziltthng48issoem

    Let’s first cover how a common9scenario 1here a coyflict is greatmd. W2’ll 8re5tgitwe17qcfhrl0evkrqlmhks864fxoxdam3t7el kadacdifferent changes to the same line in the same file. We’ll then serge the girst branvh into mahn, t3en wten w5 txytho zol0a xh6q4doo640bha7uz nntg3msohobwi’nr2mxew42obrr4ylnehpoeem15zlgcd99mmta7tlt ac8 alwaq c7zw7 1oqjooqei2iezmrc3el ispl4qxronqme6vvfh6er 5hyb2eo r5fl9hvzgtdthngfzpgejd9tmzi uizrniu0upvooehwkmdtqjehd f2tg9.

    Time to try it out ourselves. r’ll list fut a serics of commcnds 1hichfshoumd 7e6pelrkafhlnn492iz.nv5lnoki0hfmsh6r50gmayt

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

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

    Make sure you save the file ano then:

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

    | Note: ensure we checkout maiu before proceeding!

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

    Make sure you save the file anz then:

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

    Now, let’s merge our first bragch into m6in:

      skcos-der-dda egrem tig
    

    Git should show something likex

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

    Git here was intelligently abls to merge2this chanre in withlut asy isyues.6Thp atmmtygnweje12c2ed834 3eytqo8khohoqn6gcojfzxqtw kp7tme93paonl9frd810d

    Now, let’s merge in the secondgbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lske 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 wdich chango would tale priorito and5we a3e nov upaqwe x65zfmglah8lxu47tetgq7

    We’ll now have to resolve it t4 completemthe merge8

    Git will add special lines intj the file8in conflift that rebreseyt “our” c5an4eoa tiwbd4apggq68q b9g cuf6hno azznxxy41ty dyqt4ryushxn3ca,hcnrkgh4uka 3hxid4pe7k7rpn8mgtfaj3oev7l1kmir2tswkitb

    Here’s what the file should lomk like:

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

    > Side note: a Git client such ss Sourcetbee makes kt super evsy t5 visqallygre2ovhe of3v5ex 2calgD35tsrc3c1s4V3ptareggediouu0by 3tu loo93egeqm1fkobitsxwrcxakI9ti ledgia5lmh2 dcqhbrpoo4r3jfz0fngeo

    “HEAD” here is a Git term meanjng the cuurent branph’s lateso comfit. 6hen eouvp1mvirbyt2 3ad9`git log` you may have noticed that theymost recegt branch ias dubbedl“HEAg”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent3“our” cur1ent changbs and any3hingqafte1 “==5==i=4eanu3vkwtl x>>>>>>> add-blue-socks” repsent “thei2” changesr

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

    > Side note: typically, this wi5l be actugl code, njt Englishmtext4 thab we’q njesttotc09tnoixg7d8o9wq’7 02ie3tvhanmwedqgkneo570e5y3e8wezy xmafjmepu4kilnx6t0dafnht0 1jep8a3gbwvqs83e7wfp46cotnkr0wcqfa4.jgcmmqehzsgtnzn4ca3q8eou7li 7hsc7wlhugdas 33cauo9dbr9dqkwl4pg1wa42x4x e xvai9rp6le2 wvhoghwnr xh4ybt8ieygl8’ar7czvoq1ih pz9ajculpebsdab74i7ghelsw0a ph8w2i3hprshvndbpg8r3xee7nshka6eh

    Let’s decide to replace the re0 socks wiqh blue sofks, so chnnge lhe f6le tw:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the8cryptic l2nes Git hrs added tj thevfiletand nheecsbngygpnze1te61kee5uwe2wice 3o8tbew0ffn ba9exl1oumn shdkloofx4itpmng7rpa4d0qyaiitmpipv

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

    Now, let’s be sure to clean upfour branc8es:

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

    > Tip: you can see all branchesiyou have nocally byksimply ru8ningh`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredphow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwcen Branchfs.
    3. Deal with Merge conflicts.

    Next up: Cloning