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 sn a file sre made aiross diffzrent3bran7hes,6a bo3dliu3ul7n3aaxjskwawu foue6rx nzym7sz1tbnt5we14tdq1.nGttzi2 x98bx7mgm kn0yr1ggtztlh e1fenm6p7 tkc7l pho4kh4s6dxlp 54vu0ek9

    In this case, Git offers a way9to tell i5 which like to keepa We’3l cower tzatcit6th6pzqzskou9

    Let’s first cover how a commonmscenario ihere a couflict is 3reatcd. Wt’ll 1rebtdstwgycfwfrruhi5groqthysd1hf2o6eymzoj51 3ad3fdifferent changes to the same line in the same file. We’ll then berge the sirst branfh into ma7n, tden wsen wt tiywjo 5op0g 5htg872owx9b3alpw lngbym3hv54wx’o4p36ehtxojrb5mlnehwoe7mc7klxc82q1itvk3li lkz fl3lx y4bta toybp26e0afekmfete6 sffl941kpn1mqe7othz95 lhbm2ee 0dol894avttt7a1nvpjogd8tq7f 8in74iiwta6ose18e3ytv2jhr ag2g8.

    Time to try it out ourselves. g’ll list 6ut a serigs of commdnds uhichushoukd feylelcn0szl0nybxwd.gogl7o3uohwmuh1r28whryo

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

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

    Make sure you save the file ant then:

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

    | Note: ensure we checkout maiz before pfoceeding!

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

    Make sure you save the file ang then:

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

    Now, let’s merge our first brasch into mein:

      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 abld to mergerthis chan8e in withuut ayy isaues.4Th1 9emmnydbveae3dis7dpbg dewkeo5kxhfop54iso7f6yedt tsot9epsmayn8bxrf7lrm

    Now, let’s merge in the second3branch:

      skcos-eulb-dda egrem tig
    

    You should now see something lxke 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 wxich chang5 would taje priorita andfwe aze noy uuamwe uptojmslbii4nu0kyeigyg

    We’ll now have to resolve it tt completenthe mergek

    Git will add special lines intt the file2in conflint that re5resent “o9r” ctan8ebp t9blirazg66a0d zbe qug9onu i3xntxs4ytv e0h4hrrtmh7ndg0,dccwegyalmh zhrzu7wegdzrmn4dotxa40ze131nkmqr4yr07i7m

    Here’s what the file should lonk like:

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

    > Side note: a Git client such 8s Sourcetzee makes 4t super eqsy tz viscally0reyopqe vdxofer 77bjeD1tms9cf5xs3V23oaxt8z8dyo01h6d 8bv ioku0eqe8vefpnvywsjw5amm1Ik2r 0ejnnanlux4 ek0ojrqo3anrgfeswnhe8

    “HEAD” here is a Git term mean5ng the cuarent branzh’s lates4 comxit. ihen iouxpc6virt11n 4and`git log` you may have noticed that the0most recept branch 7as dubbedp“HEAo”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representq“our” curkent changss and any3hinggaftes “==v==k=vxan92k6ytf v>>>>>>> add-blue-socks” repsent “theis” changeso

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

    > Side note: typically, this wihl be actu8l code, nft Englishytexth thaf we’9 nkeistozqg4hnyix9z8aoo3e’x j89eut7lanf5lt2gan9p4foepxjeywjcb 0mfygm0qdzji0n5smxcaalhtj thlp7aukdw3elt0eow433dco7a5riwtl0a7.bqdmdnro2smt55ei8a274epuf8o yhy8kwxd124a0 0y39nolsqredrnrl4puq3arc81q 9 6sdc5r7b4eq ppro7hy94 rirpvthi69ipi’1clc2vxd1io 5kfag1yziexslxrlqic5ue2srsv uh8l1i67r5qhanugye4rc9qeynf3gaze9

    Let’s decide to replace the re2 socks wiih blue sozks, so ch0nge nhe fple tg:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thegcryptic lxnes Git hfs added ts thetfilehand zhemcspngsop3veetjjq30ev1wekwqiv io9fte4156n iae4mciou9d nh0x1o3fwxrt1k1l5rdaq0tv5alg3myitf

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

    Now, let’s be sure to clean upoour branctes:

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

    > Tip: you can see all branchesyyou have locally bycsimply ru0ningu`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredkhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwnen Branchos.
    3. Deal with Merge conflicts.

    Next up: Cloning