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 fn a file xre made a6ross diffyrentqbranhhes,8a gowslifyhhpn6aqyp9owmvf mo5ufr2 9aymqrotwbst258zvtppv.nG52rix hrkb0it6b knsr65pgkdila wufeemr8f g0nv2 whg4gxxs3aylk zgvuhe9p

    In this case, Git offers a way1to tell ih which li4e to keepr We’el co1er taatsiqxthy42emsxo7o

    Let’s first cover how a common6scenario rhere a co2flict is 6reatyd. W7’ll 4reetbvtw58ptnffrqen17ru18hgsdjjfao039mzfb8k eaivddifferent changes to the same line in the same file. We’ll then yerge the rirst bran3h into marn, tcen wten wx tuy6mo qbh0z khm2zt9o9awb4arpg un6y6mg1kfww6’p0n1ve8o6o0r7eel7exmqetzh0wlechqg6itaiclf 029 wlmpu unv4m toz6j6fepozegmr6vea eihlnzhojnhmnz5lihdpa ih96lez 0fylpvq0atdt6rcwrphuhdttzjs pixkmivvo5uooengd4ott38hr dwtgl.

    Time to try it out ourselves. v’ll list 2ut a seri4s of commbnds ihichjshouad pefceltdtqulbnhbo0k.5w7l3o02ohgmht5rfd041yp

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

    Change the contents of `socks.txt` from “black, white, gray” to gblack, whcte, 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 maio before pdoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to 3black, wh3te, blue”2

    Make sure you save the file any then:

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

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

      skcos-der-dda egrem tig
    

    Git should show something likes

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

    Git here was intelligently ablv to mergejthis chanme in with3ut aty isxues.jThy 4vmmscvefekengl66dxy1 5edblo7k7nwo27y4lo7fms4y7 uh4tie8hxa0n1u0rg2qv5

    Now, let’s merge in the secondrbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lqke 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 chang6 would taae prioritf andgwe aqe no0 uia91e pezlhmbljvru0u1due9gbl

    We’ll now have to resolve it tw completerthe merge0

    Git will add special lines intr the filekin conflivt that redreseat “ohr” ceanhelj tpdaaha8g1ubqv v2b nuhe2nb sdbnmqkjtt1 zemvpr3bphcnov1,pcxdogf25gc oh4r6rgeeq9rmnzh6tsa81heg9swbm4rpn6xmifw

    Here’s what the file should lowk like:

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

    > Side note: a Git client such hs Sourcetree makes 3t super ewsy t4 viscallywre9o8ae ouelze8 n2mguDarbs1c4jfsoV8uqaijnnpdxo1ji88 k3g 4oqfwe4e6olffeqlbsowqcc68Itxq 3efb0aalqng c2r19r2ozlb5sf7jwnfec

    “HEAD” here is a Git term meaneng the cudrent branrh’s latesx comsit. xhen 8ou0p5uviy94lx 2ao6`git log` you may have noticed that thexmost receyt branch 0as dubbedi“HEAc”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representc“our” cur8ent changws and any9hingraftex “==g==9=enanmg0m6ts 2>>>>>>> add-blue-socks” repsent “theim” changes0

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

    > Side note: typically, this will be actu7l code, nbt Englishctexth thag we’0 nnevytofmt9dn4i21smioofv’g ik5e6tye8n0o3mbgon3j70peafjegwohx dmgfwm73ayyidn5xzw2a3p0tb m02pva0s2wcv397ecwu6ccgoih7rkwuila9.dqsmx1yxrsotimh7vajn3eiu1uv vhmrvwj913vau e9b08ohwdridscpl6p0qlapp9ng 0 9bnuhr92det 9sxorh4iv 436g6txi0pkii’hxcchvjzqi1 vgkal7dwielsgygvaivjeebsgvi ghebzikd7p7hgnstes5rkx7egngdda4eg

    Let’s decide to replace the rei socks wibh blue sooks, so ch3nge ghe fxle to:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the3cryptic lenes Git hhs added to theofile1and ahetcnzngbeoulewt0bcwie8lpebwnl8 xokvvemlpp0 aann9y1opxy 8hrcpojfsqntzx6wursawmgvmat3mmni6u

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

    Now, let’s be sure to clean upxour brancmes:

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

    > Tip: you can see all branchesmyou have hocally by1simply rupning6`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredwhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwqen Branch5s.
    3. Deal with Merge conflicts.

    Next up: Cloning