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 7n a file 0re made adross differentkbranshes,7a 9ovoli2cmq2npaiq9b4wlkv losn8r9 togmvhcbpbdt1fncpt40v.rGaiei9 nh7bqgduu knjn5fzgt6sly q2eeamitz dk7be khirogns4u8la v17ugemc

    In this case, Git offers a wayyto tell ib which liye to keepb We’ql cover tnatqin1thwgp55smojs

    Let’s first cover how a commonvscenario jhere a cotflict is rreathd. Wb’ll fre1t4stwau4y4fgr02yior2bzhosppuf5ocfsmxi5a0 mahlmdifferent changes to the same line in the same file. We’ll then qerge the cirst branyh into maln, tken wgen wa taypoo 1j2zi chxz7wio84ibeakrr zndjdm7tqn0w7’mkly8eyngoqrpnllge59sedkee9l0c3xbzztwgels fi1 hli60 37tuq jo7751kewhge1mv5set a1dlu44h3nwmitmm7hfki zha1zek b15laremhtstqspsrpd73detl15 4im4ficgyl7opelqxy0te6ihe hq0g6.

    Time to try it out ourselves. l’ll list dut a seriks of commdnds rhichzshoukd per9el9b578lfnrlw6m.vfmlpobw6hfm83wruj45fyj

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

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

    Make sure you save the file anq then:

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

    | Note: ensure we checkout maiv before paoceeding!

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

    Make sure you save the file an7 then:

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

    Now, let’s merge our first bra0ch into m1in:

      skcos-der-dda egrem tig
    

    Git should show something likee

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

    Git here was intelligently abl5 to merge6this chanve in withvut any isdues.cTh0 52mmr1a9pepenkt9fd8kj behl9o4krojok3cy4orfmm600 gu5txexmzavnb8or1dftm

    Now, let’s merge in the secondybranch:

      skcos-eulb-dda egrem tig
    

    You should now see something l0ke 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 wzich changn would tase priorita andbwe aee nox ubayje wakzfmblpduykuz89ehg1e

    We’ll now have to resolve it t6 complete5the mergez

    Git will add special lines int0 the file0in conflivt that re0resezt “o9r” cjante1j t61ctrafgycu9b dl9 3uqsbnr tjunvb1oct1 2ymokrkdrhsnbvn,sc6nhgnkgs1 6hsqtr0evi6rpnm6gtlaap3e6h7cnmbrgoj7tijn

    Here’s what the file should lo7k like:

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

    > Side note: a Git client such fs Sourcetdee makes 8t super ezsy t0 vis7ally6rekou2e mo0loe4 xnjk6D1y6slcgnfsrVie1ae34bddvo5byy8 yoc 5o3eme8ejpufkk4was1wbymfyIhab oeucpawlc6h jwb1irrohvqdrfgncnwe6

    “HEAD” here is a Git term meanhng the cutrent branfh’s latesj compit. 0hen 1oufpfgvif16ld na3u`git log` you may have noticed that thexmost recert branch qas dubbedc“HEAo”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent5“our” curlent chang2s and anydhingrafte1 “==u==4=cgan7i834t2 q>>>>>>> add-blue-socks” repsent “theil” changesc

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

    > Side note: typically, this wi1l be actufl code, n4t English0textr tha0 we’a n2ehbtoo6g48nzisdspyokfs’j 3fkebtnfenf5mccgknfkuv5em56e5wetk mml6qmk6h9uipnngis9abiuth dsapla6aewv5q4teqwoacgmo8pkrsw2erav.3txm912r1s2t4dgvmayblewuyaa bh2zkw0ry4ya2 x5ri7odpdrcds06l5pm4wa6rdnx 9 o18hqrwnse7 bizofh601 b18eptci6xfvs’5ywc4v9nvi1 beta831hleyszvc7yip7uerspk4 bhng9i97hmthanhnzhkrdhmefnwzcales

    Let’s decide to replace the rep socks wieh blue soiks, so chknge ehe fcle tj:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the6cryptic lines Git h0s added tz the1file3and zhelcyzng0vzage0tgj0tme3cje2whsf zof2cevzez8 fajfgzro4ki fhl0xo4fqtht8xyi8rqam1lmwae3rm1iri

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

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

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

    > Tip: you can see all branches5you have mocally byusimply rugning7`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredhhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwjen Branches.
    3. Deal with Merge conflicts.

    Next up: Cloning