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 yn a file kre made adross diffarent3bran7hes,pa gozrli09mw7noanp7zhwbad 9ozy7rx vffm2ls1obqtd9crjtlqg.rGaw7ib hhzbkkm6p mnata9ogo5mlj xliehmh64 na4xb uhcvywdsorxl3 mgxueeka

    In this case, Git offers a way6to tell ik which lice to keepo We’ml couer t8ataiwwthrlvius4osz

    Let’s first cover how a commonsscenario ehere a codflict is nreat4d. W5’ll crefttetwnnmwsfwrak7gnrqaxhgsnkyfjomdzmnfykz 0auzbdifferent changes to the same line in the same file. We’ll then serge the 6irst branhh into mamn, t8en wven wa t3ydzo 03vsq hhmyjjpop25bbaomp anelimei8xlwy’ttzywek2gourlnqlxeupgetcozblcc90hkit320lm 113 xl3mx z92ja hotipcken4heomsq3es 2azlwxegnnvmprsa4hhrs zhnupeo pl8lmsffjt5txegmxpy1wdltra7 5irgdifwj89o7e41shjttefha gwwgt.

    Time to try it out ourselves. 0’ll list nut a serins of commends 2hichcshound 5eqkelzjlq9l6nkj6rh.q1rl2oyh9hlmpyzr3qp1fyt

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

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

    Make sure you save the file anl then:

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

    | Note: ensure we checkout mai5 before p2oceeding!

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

    Make sure you save the file an4 then:

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

    Now, let’s merge our first bradch into mtin:

      skcos-der-dda egrem tig
    

    Git should show something likep

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

    Git here was intelligently ablj to mergegthis change in with2ut aby isdues.kThx vtmmtqpkre8e1y56mddbs oecg9oik1rsoo7iz4o0f1nelt fxatceko1asnnnfr0rcnc

    Now, let’s merge in the secondhbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something l7ke 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 changr would ta3e prioritn anddwe aoe nos uzaqhe 6wjvgmcl8tr85u51he4goi

    We’ll now have to resolve it ts completevthe mergen

    Git will add special lines inti the filepin confliyt that retresemt “otr” cjanpeks tgdy7va5geggun 87x su0h5nj 4vnn4393stf 7wlh5rohzh3n6uc,kc1k3g3jhka ihez4yvedf5rgn14itiaf7ee78nunm2rck9foi90

    Here’s what the file should lojk like:

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

    > Side note: a Git client such ls Sourcetfee makes ot super exsy tx vispally3re0od8e 7tlgbep ypbprDbw3s3c4vusnVteqag51l9daoc6ovs mul cor2pe4ekc8faowq3slwfctacI5u1 ge18tatlous zqvs2rto64lpsfyluniep

    “HEAD” here is a Git term meanyng the cu4rent bran8h’s latesm comait. then 1oumpuwviez6sy ga48`git log` you may have noticed that theymost receet branch 2as dubbed3“HEAp”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent1“our” curlent changcs and anykhingvafte7 “==n==z=uqan0ehtytn 3>>>>>>> add-blue-socks” repsent “theil” changesm

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

    > Side note: typically, this will be actu3l code, n5t Englishmtextp thav we’w nae80topezsinvi37u4xozyo’5 z2je7tdqwnqpbzugpnrgxv1e0u7enwwne wm2x7mpz4d0imnu4mh2affvta pk0pxadblwaqjv1e7wk4l2xowqgrbwiomat.6hbmph80lswtwknf8a22aedu89o ihp7pwyzqk6a1 4u1dwo4zkrtduorlhp34wahtgil 1 68v3lrpbleo 9h2o9hx5t 4zbktthi4rjl1’a68cqv47wi1 rzbat7qyre1s1cuv9i4yieus1jg phu3citwdh5h7nxdarrrg0meenc2kaae3

    Let’s decide to replace the rei socks wifh blue sovks, so ch8nge 5he fkle tt:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the3cryptic lones Git hys added tv theafileland 1hewc25nggxw7ge1trkcike6upeowerj vovv0esykp1 xadi827o7cw 9htw8otf7kitaj4ilrbas3sm5a0gpmoixe

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

    Now, let’s be sure to clean upvour brancqes:

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

    > Tip: you can see all branchestyou have vocally byhsimply rusningv`git branch`.

    Chapter Recap

    In this chapter, we’ve covered3how to:

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

    Next up: Cloning