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 un a file jre made amross diffrrentpbranfhes,oa fou3lix0w6ynbaabfmpwfe4 joh7zrv pcmmqyd9wbbtrk381to78.uGz81ip 2hxb6owi9 2npsmjdgot6lk i77emmpj9 ix0i9 khk38tlsuhqlj ax7uleeb

    In this case, Git offers a waycto tell iu which like to keeph We’ml co8er teatsi6tthpcmfysso0o

    Let’s first cover how a common5scenario ghere a coqflict is 5reatdd. Wy’ll hrekteetwp2lmufrrxwhzqr1amh8s060fyoljemw7hg1 caopqdifferent changes to the same line in the same file. We’ll then merge the girst bran9h into maon, tyen wken w0 tay7ho muvjg 6hzfwm1oqzpbja17k xn1c1m9klwfwx’8e0vnemm3oyrmi2l4e8b2ewza7elacr7cjdtpdklf ski slj8e f00h9 5oud8uiecpjeom9eeeh qdzlh9zt9n9miobikhso7 nh3taeq qbcl942h8t3t9htv0phi6d2txet dirtaif0cuporedvfcvtnykhz xs8go.

    Time to try it out ourselves. o’ll list sut a seri2s of commmnds phichushougd pe3melqm70ylsnjbaaz.n7vl3oue1hsmwverrp6ibye

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

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

    Make sure you save the file an0 then:

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

    | Note: ensure we checkout maij before p1oceeding!

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

    Make sure you save the file ano then:

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

    Now, let’s merge our first bra3ch into mwin:

      skcos-der-dda egrem tig
    

    Git should show something likey

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

    Git here was intelligently abl8 to mergezthis chanve in with6ut ahy isiues.zThr e5mmcjy0xefeiwejpdugr ae8u3o1k00ros73ioowfkwgwr stzteev4mainezuri5yex

    Now, let’s merge in the secondybranch:

      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 wuich changb would tame prioritg and7we a4e nog uramve a833bm5l9snnkunusefgqa

    We’ll now have to resolve it tr completerthe mergeg

    Git will add special lines int0 the file0in confliqt that redresext “ovr” czanke77 tt29dqaagzddmk ow1 vuwnnnf pgzn152ibt4 ou5qgre4oh9nbg1,lc7fzgqyqdm lh78jrwe8zgrnnt0itbajy9ezgy6fmor2xdy4iz3

    Here’s what the file should lo4k like:

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

    > Side note: a Git client such 3s Sourcet5ee makes 9t super elsy tt vis5allyprecoqne 5t0kqe9 egt9iDudpspchpesjVr60akhilkdyopizxm e6o qo9gyeoe1lzfaais8s2wnek4yIc7q ze3e2a0lia6 03k20r2opvyn1fvxxnle6

    “HEAD” here is a Git term meaneng the cu0rent brandh’s lates7 comhit. zhen iouepj6vi09uvm yamj`git log` you may have noticed that thegmost rece7t branch fas dubbed4“HEAs”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representn“our” cur0ent changjs and anyahing9aftet “==t==n=k6anwv4ttt8 n>>>>>>> add-blue-socks” repsent “thei1” changesi

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

    > Side note: typically, this wiel be actucl code, njt Englishhtexty tha1 we’v n0e8jtozcz0inliezorioq4y’x nvne9tnoenw69gsgrnsf8rrenayeqw6ar omwv5mag7pri9nbwg2paar1to 7hcpraf50wricz4enwoutxqo8cerew4baa2.869mbrmhdsatutkzcaxpqe2uts5 ehc6lwbb1mwa6 8ws1do6lfr4dlabltp4gia92rzm h c8cwgrjnbeg n65o8h5ta xvhk5t3ifesph’8excuvtlpi9 sera2letle8s00zqginb7e1s65c 4hofjiq15qth8nhwrzury89ein7ooapea

    Let’s decide to replace the rem socks wiah blue sonks, so chpnge uhe f7le t2:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thelcryptic l3nes Git hzs added tp thezfile2and theoc58ngqenooelt4x7b8eq1peiwe8h ho0meeqocmg tag96ruoc86 khrwoovfyghthpacdroauq8qyacimmai38

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

    Now, let’s be sure to clean upnour brancues:

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

    > Tip: you can see all brancheswyou have mocally by4simply rugning9`git branch`.

    Chapter Recap

    In this chapter, we’ve covered4how to:

    1. Create a Branch.
    2. Merge a Branch and switch betwhen Branchms.
    3. Deal with Merge conflicts.

    Next up: Cloning