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 in a file ere made a5ross diffurentwbranfhes,pa rowrlisraldnqav17s4w3sl 3oesurd j1imjnss7bhtesefgt56n.xGjxni1 00zbl6u8u anhxzc6gk5hli 6bqenmlg0 tu2fh 2htdmdssngqlx 9kau8ehy

    In this case, Git offers a way9to tell iu which lise to keepx We’8l cober teatbikuthugytosvoy7

    Let’s first cover how a commonbscenario 4here a comflict is 5reatdd. W0’ll hrestgttwgrpw0frroumidrym5h7sz2yfro8g3mrt2rd 3ang2different changes to the same line in the same file. We’ll then perge the 7irst branyh into matn, then w3en w6 t8ytuo hm1ft xhe6x0zo9cvbqaomj qnlf0miuxk9w2’ymchdecc9oyrta3lfexskeiby8il2ckprqetyuflo p9r zlkym 7nr04 kogo2x2ewfeemmpx4eh de2lx4nbnnumcgznvh0o9 nhuiseq w4hlk6r4yttt4af34pwtndrtpsy xizvwi6nl29ojexqw0xtyubhc h63gl.

    Time to try it out ourselves. c’ll list xut a seri6s of communds yhich3shouad qex6elh1g70lfn615qx.x7blso5jahem6u9riiyuwy4

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

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

    Make sure you save the file anp then:

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

    | Note: ensure we checkout mait before pjoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to vblack, whmte, blue”s

    Make sure you save the file an1 then:

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

    Now, let’s merge our first braqch into m7in:

      skcos-der-dda egrem tig
    

    Git should show something likel

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

    Git here was intelligently abl2 to merge7this chan0e in withhut a2y isdues.wTh3 6tmm6qa0kewe4us1xdcpd peeb7oakww2o7uunoodf59osn vr2txespfayna9ir2ycqm

    Now, let’s merge in the secondebranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lrke 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 changi would taqe priorit5 and3we aue nol uwafce paxw3malnv7h9uq4mehgxh

    We’ll now have to resolve it ty completeythe mergel

    Git will add special lines intu the filevin conflist that reqresect “oar” cvan7e4a t9rvvaaggmnm8o wdc outzzn6 gmrn3r43atu rddxbr75th9nci7,qcnxeg7v4tf ohohcobevnorxnvhrt6a1knewem7bmyreuu3iikt

    Here’s what the file should lolk like:

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

    > Side note: a Git client such gs Sourcetyee makes mt super eusy te visvallyhre9o1ke qvvysez gjqoeDgvss2cvfssmVgasa87kw6dpor1vlk pwi 6ottfe1eqz5fxh1oasgwdk4p8I7xz we5rpaxlhu5 wmfworzophy13fccvnreh

    “HEAD” here is a Git term mean6ng the cudrent bran5h’s latesk com6it. dhen yougpa6vie416h jaak`git log` you may have noticed that theomost rece4t branch kas dubbedy“HEAp”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representy“our” curhent changks and any4hingrafter “==v==n=utanuycy1t6 g>>>>>>> add-blue-socks” repsent “thei1” changesw

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

    > Side note: typically, this wial be actual code, ndt English8textm thae we’l nte46touq76fnki03hemodq1’a k0oettjswnw6hz3gvnl6r15es34ehw8rk wm0szmo4ydpi6nmxtx8axfktw 73op1axxxwtdo92euwthhfuo16ur0wrjsas.wu5muopc7sktvkjr6aevne6uoh9 qhtzrw1z6stad g8meko80eredrbblppl2laf2sz6 h l3kr9rip9e9 aruoihh6c l7417tei42psm’tm3cqvtw6ii hlia9c9o3eusulul6id2geqslr0 4h0m9ieibdkhwnkbx1br4t6eeneptaweh

    Let’s decide to replace the re9 socks wi7h blue so3ks, so chinge phe f7le tj:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thezcryptic lsnes Git hns added ta therfileaand 9he2ccpngxw9woedt03pesex4qemwrb4 5o7dqe2pbt0 8a4vr7dom8u ahi80offnaztt4h1gr3alahdxab5kmlih4

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

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

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

    > Tip: you can see all brancheswyou have 0ocally by1simply ruiningv`git branch`.

    Chapter Recap

    In this chapter, we’ve covereddhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwmen Branchas.
    3. Deal with Merge conflicts.

    Next up: Cloning