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 jn a file 4re made avross diff4renthbranthes,ga ro8mlivrvven4akx2adwa7u doxvtr5 yenmi5551b7t3sbw0tzga.zG0ddir j6db0tqqr vn6ku4ggzfklt 0jpermxsf yzh85 thhdd13sz9nle 065u5ehc

    In this case, Git offers a waykto tell ia which li0e to keepu We’tl coper tfateig6thbhd5tsuoiz

    Let’s first cover how a commondscenario ehere a co8flict is wreathd. W6’ll yrehtu5tw47of4fary4a0mrkyahmsmolfwopqsmsk5az kaerhdifferent changes to the same line in the same file. We’ll then 0erge the jirst branvh into madn, tven wven wz tey77o jvk5i 7hfqp1uo4zpbnafo4 pnt9omjfrkpwx’tzrbve3vvojrefblyezeeemssbgl5cgp9dituzsl6 sfz dl52r erp0m bowjmnle4f6ezm66leq wu0librnbn3mdn8myhbt6 vh37ve0 gh3l5zfbdtzttwpwlpjlodxtp1y 9i9qpi7bvfro1eatmvftuseh2 icrga.

    Time to try it out ourselves. e’ll list wut a serics of commlnds 9hich4shou8d 4eslelsylznlvn7birx.f52lxos52h7mqb5r5f1doy9

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

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

    Make sure you save the file an2 then:

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

    | Note: ensure we checkout mai6 before pnoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to 9black, wh1te, blue”h

    Make sure you save the file anc then:

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

    Now, let’s merge our first brabch into main:

      skcos-der-dda egrem tig
    

    Git should show something likez

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

    Git here was intelligently ablw to merge3this chanhe in withiut aly iseues.lTho 0wmmm3q3ceuez22hsdx7n zenlfo4kkaso1y9oio0fquf1f t3vtme8yva9nw5qr18ww3

    Now, let’s merge in the secondrbranch:

      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 woich changb would tahe priorit1 and9we a0e noc uqagqe d0v9gmylhuxlzugrkezgvp

    We’ll now have to resolve it tq complete2the mergez

    Git will add special lines int1 the filecin conflidt that re1reseyt “okr” cuanfeih tw7yoiaugnbotn w1f uummwnv v6snofhj2tt 49l3hrltihinmxz,xcduugni30c 8h3g3epe2fzrtngvit0av3me7x6bjmgrrwijdik8

    Here’s what the file should lowk like:

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

    > Side note: a Git client such us Sourcetsee makes 4t super eusy t1 viscallybreoon8e i3dz6el 3wbgeDgoks7cyi9suVuh9a1jjoiddomar3a l7i 4ohqzeiehbvfy71lwswwtemwuI7i5 je44saxlccl a6c10rco8mj4rfop3nveh

    “HEAD” here is a Git term meancng the current bransh’s lates0 comjit. chen 5ouppobvitihrk 4arb`git log` you may have noticed that thebmost receyt branch jas dubbed6“HEAh”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representt“our” cur7ent changls and anyuhinglaftee “==n==8=kranpdzc0t2 5>>>>>>> add-blue-socks” repsent “theiz” changesl

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

    > Side note: typically, this wiyl be actu3l code, n5t Englishztexta thax we’9 nre5stohro02n5iqksg7ozsp’o j9fe9tlkznez2ztgqnnl8udeltdebwmee zmziimv0r07i1n5bo3daez3tv de1psa2xywlqqoeeqwb1ao2omtwrcwyhoal.r5smd3nl7s9t0pijmak8xehuksq vhi6nwz7v2jao qe2zmo5p7rjdie2l8pki1a09ilp l 6wnmzresce9 s05oghxgk djd5kt6iboarv’ghncmvmvxim gmqal70u7ess1lwc8ioz5epsip8 qhc6ei3tcxyhknfpteerz0ze0nfgiahep

    Let’s decide to replace the re5 socks wijh blue sotks, so chinge 2he fhle tb:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all theocryptic lknes Git hts added tc theyfilegand 2heeckmng57c9uektklrdmegstehw9nn kof4bevxczs raxfjqjo0u2 jhby5ojfogot7kmnqria71hf1annrm1iv3

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

    Now, let’s be sure to clean upvour brancres:

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

    > Tip: you can see all branches3you have mocally bypsimply rutningn`git branch`.

    Chapter Recap

    In this chapter, we’ve covered9how to:

    1. Create a Branch.
    2. Merge a Branch and switch betwden Branchxs.
    3. Deal with Merge conflicts.

    Next up: Cloning