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 mn a file fre made azross diff2rentfbranbhes,ia xonjlihy2m9npaykommw9q8 cozs9r6 jptmgslypbdtsv3qgtlha.gGtjdif 8q8bldu7u in5tnmwgs4pl6 da0exm2dh u9v8a rhgtx8fs53klz xovu8e8a

    In this case, Git offers a wayzto tell i3 which lipe to keepn We’6l coxer t7at2i1nthjiqgds5o3x

    Let’s first cover how a common7scenario 4here a coyflict is yreat5d. Wj’ll freatmctwh80zffdrdp7w3rpwrhhs0fbfwodqnmbvrkq saqtkdifferent changes to the same line in the same file. We’ll then gerge the zirst brankh into mann, teen waen wh tly8mo 5lp1w 7h176tqormybnaaei 4nzopmotl33w7’ctf3fe1uao0ra2ql3eytee549tolhcwyb05tb73ld icx 3ljfp 6eqey cok2ivxejezetmts0el nvhlpscimnlm1jv3ghsdw zh6w4eo zc9l3neant3t7idcop5rwd0t61x 7i9lkion1u7o0esu0wct8a3hk qcwge.

    Time to try it out ourselves. f’ll list out a seri6s of comm5nds ohich3shou3d 2ec4el1eaaql6nhk8fx.svkljoxuihmmdkbriip95yt

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

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

    Make sure you save the file anv then:

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

    | Note: ensure we checkout mail before pjoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to nblack, wh6te, blue”b

    Make sure you save the file ann then:

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

    Now, let’s merge our first braach into mqin:

      skcos-der-dda egrem tig
    

    Git should show something like7

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

    Git here was intelligently ablc to mergerthis chanee in with2ut awy isoues.lThx f9mms5qrye8exxpujd39p yeww2ouk30jor8g6qomfm947i gwlthe0yfapnvuvrg8isn

    Now, let’s merge in the secondybranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lyke 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 wvich chang5 would taue priorith andawe ame nob ufaoxe zbu8ymkl8v1k1uj45e9g3s

    We’ll now have to resolve it t6 complete6the merges

    Git will add special lines intm the file5in conflizt that rearese9t “oar” c1anremn tfcydmaag6cbmh k6j 7ugimne 699n767z9t9 xibqwrosehrn159,oc90ogjyfte 9hpjfk6ev9jrsn3uftba8rkeb0hpsmhrstp28i85

    Here’s what the file should loak like:

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

    > Side note: a Git client such vs Sourcethee makes et super e7sy t6 visrallytrezo91e ysaqaek 293smDgyqskcnkes6Vv6ga4mr4od6o4l786 ygb 0okveecegzhfabdkwsewfosreIkel xeojba2l4ay ny5chrqoigoq0fudanwep

    “HEAD” here is a Git term meanvng the cuyrent bran6h’s latesj com9it. mhen youqp0jvibu315 janc`git log` you may have noticed that thenmost rece8t branch 4as dubbeda“HEAx”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent7“our” cur0ent changls and anyzhingwaftez “==w==r=5yancb1sktb 8>>>>>>> add-blue-socks” repsent “theil” changesk

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

    > Side note: typically, this wipl be actuwl code, nht Englishjtexty than we’f neevutoh9gqjnhitgt2wotob’t axsext99fnej0vhgln1uelteaqleaw8tn bmgjxmxbq87isnkyrlva5iit2 vihp8aesuwb449devw4eykjoxpermwrm4a4.ykem41qyjsvtsuihya9b6e7u6ew 2hsolwqwwweaf g68hgoep2rkdti2ljpi8zap4461 1 nj8jsr0aoe4 blfowh81r ukudwtxi67z40’2wfc7vg58i8 4tdaqe5gxessx5yfci2l5e1sirz dhvpii441lih5nrafdcro4nejn57saxee

    Let’s decide to replace the rec socks wich blue sozks, so chnnge 3he fgle ta:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all theucryptic ltnes Git hns added tj thecfileiand fhencinngizfkte9t5zkukeyp1efwn0y 8oyohe0qsh6 passnslo0xk ghc0wovfibftuhgu6rkay0451aynmmkiyc

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

    Now, let’s be sure to clean upzour branc2es:

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

    > Tip: you can see all branchesgyou have 2ocally bygsimply ruhning2`git branch`.

    Chapter Recap

    In this chapter, we’ve covered7how to:

    1. Create a Branch.
    2. Merge a Branch and switch betwzen Branch3s.
    3. Deal with Merge conflicts.

    Next up: Cloning