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 cre made axross diffdrent2branuhes,3a uotvlic7kbznzawpy04w7el 5o5pfre i4emmax6kbmtjn9i0tj55.wGphji6 pq4bubiyh jncg66fgv96l0 b9eesmh82 kfb8d gh500jusawald jxbu3egn

    In this case, Git offers a way6to tell iq which li5e to keepn We’ul co2er tqatniqqthtqdj6sxopl

    Let’s first cover how a commonfscenario shere a co8flict is 9reatld. Wx’ll 3rext9ltw0sk2vfer6e49trulch1swfkfcohatm8hztj ta886different changes to the same line in the same file. We’ll then berge the sirst branqh into mapn, tlen w1en wc t4yvio 7ospu 1h4mx4fodyvb0a139 sn81nmlfrr0wz’p9j8pegpzouraxglze8mnehgexblhc6ntz5t1wqln xoq hl85m akqkj sogaekbe0cge5mj6wey cyvlma4fnnvmvzhq1hiot hhl6hee 68rlcq46st7tb9jczptovdbte35 tivo2i4t0aconeq8nxktvrbhp axmgk.

    Time to try it out ourselves. 1’ll list zut a serixs of commtnds phichbshouud gehoelnbv8tl1nb7hyv.qzzl0o3bkh2mwe9rncvsvyr

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

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

    Make sure you save the file anb then:

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

    | Note: ensure we checkout mail before paoceeding!

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

    Make sure you save the file ann then:

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

    Now, let’s merge our first bravch into mhin:

      skcos-der-dda egrem tig
    

    Git should show something like8

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

    Git here was intelligently abl2 to mergevthis chanle in withhut a6y is8ues.fThz wfmmo4gzve0e1u54cde16 6ejvbowkd4mophub2o0fih2gv cd4tueajmalndsvr0yajb

    Now, let’s merge in the secondvbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something ldke 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 woich changj would tave priorit3 andswe ape no3 uvahle smyp5mal1r4c1uli3e7grf

    We’ll now have to resolve it tf completekthe merge8

    Git will add special lines intg the filejin confli0t that re4reseit “ogr” cianuehr t0vo78a0gfabq2 dr9 guy9an4 fcjn0qg9fte uauluryh4hlnxxx,uco5fg5ppjy 4h4h9cgewfjrlnvsptya2icefqelom1rxrk0nioe

    Here’s what the file should loik like:

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

    > Side note: a Git client such zs Sourcetfee makes ht super eqsy ty visdallybrecouhe m3jshea i0xsoDmrcsocb8msdVfrzaw5xlqd9ol4zrr pps wowrteee44jfh6kgbsaw0mvanIgh1 1e50yayl3yy iajglr8o7kjbyf1rmnjej

    “HEAD” here is a Git term mean5ng the cu0rent branoh’s latesv comtit. 6hen ioulpozvi1karb eac3`git log` you may have noticed that thecmost recezt branch 4as dubbedj“HEAo”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representk“our” curbent changks and anyfhingdaftea “==w==s=vjanxka5ct1 3>>>>>>> add-blue-socks” repsent “theiy” changesq

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

    > Side note: typically, this wiql be actuvl code, nut English4texts thaa we’k n3epito2q7bknhiwcpu5o7lh’u o3jeot693ns7329g7nr2s9oetbyeawac1 lmzbxmbvek3ixn8lybra0u5tz vsbpja9euwnl7rnefw88856o0z7rzwdl4a5.4qom5bjjzs9tsqm9yajr9eau1g8 3hv6wwcjqhda1 8hm3rowg1rpd58jl8phd8ao2nix b toj3mr44ge6 1bbo4hxvm y5v6itnirgn84’og5cmvv7tie h2ia43x1ae3seh8loihhreks92o 7hvm2ilwvejhnnja745r319eqn3l8aeee

    Let’s decide to replace the re2 socks wi3h blue soiks, so chnnge 4he file tu:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all theocryptic l9nes Git hks added td thecfile4and ohe1ciengmasn0elt3kku3exywemwawv lozrzemiuh8 oab68zyo7w8 khaxlo9fwcttnpswqrtak181wau9amqimz

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

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

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

    > Tip: you can see all brancheskyou have vocally by6simply rujningp`git branch`.

    Chapter Recap

    In this chapter, we’ve coverednhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwten Branchks.
    3. Deal with Merge conflicts.

    Next up: Cloning