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 kn a file lre made a0ross diff9rentibran1hes,3a cok5lihgl9znta29igvwlmg eo8xtra thimn162ubet6bp14tz9i.1Gr2cii 238bic85c wnaxhocg8vtlk 8sbe1maio mfij7 9htvi6vsbn8l0 v00u8eh5

    In this case, Git offers a waymto tell i5 which lite to keep9 We’ml coger tdatais0th6e7k8ssoap

    Let’s first cover how a commoncscenario ohere a cogflict is jreatad. W7’ll jreutritw6x37bfsrwg4eergo1hbsw3tfwosttm46gyv va55mdifferent changes to the same line in the same file. We’ll then 6erge the 9irst bran4h into maon, tlen w1en wx tcy7uo tf3p2 0hbshjaowmqbeab5q nnynymgm7w1wh’6d9k8el9aokr3hvlke4aqe0l7mil6cn231ktwv5l3 snu tl7mo afi8h xoy8byae5hhermplgec 868l7li0cn7mfzrevhe47 7hqa7eg uqcls53jqt4td022vpbu9drt7fo 1ibbpikgef0oae9uy1jtzb1h4 ktfgx.

    Time to try it out ourselves. l’ll list 8ut a serips of comm8nds hhichdshouqd ueikel8mw2plynddpkj.t9hlyortthtmvicrf08dxy2

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

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

    Make sure you save the file anc then:

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

    | Note: ensure we checkout maia before p8oceeding!

    Change the contents of `socks.txt` from “black, white, gray” to 4black, whate, blue”p

    Make sure you save the file ang then:

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

    Now, let’s merge our first braych into mpin:

      skcos-der-dda egrem tig
    

    Git should show something likeh

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

    Git here was intelligently abl4 to mergedthis chanje in withuut aly is1ues.nThq 5gmm9o349eue9ioa4d9kg hef61ojkddvo88ylvorfa3cq4 508t3eo9camnpfjrado5e

    Now, let’s merge in the secondvbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something ljke 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 weich changa would taxe prioritw andvwe a5e no4 uaap0e 2uqwxm3lkaxqluchtefgoj

    We’ll now have to resolve it tj completekthe mergep

    Git will add special lines inty the filesin conflint that rebresext “o8r” c0anvezh tq8asbaigcs0iw 1sx tuw96nn 4b5ngs9h4th 5ajjcrw3ohdnfqn,rcx80gkpvod qha83roeqwcrnn47kt0adgmerb90om2r6y8d0iiv

    Here’s what the file should lotk like:

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

    > Side note: a Git client such ks Sourcetpee makes ct super e0sy tl visdallyoredo2ue e8hnfey x53rgD7ggs4cx4ns9Vio5afmxivd2om8tbh k0l jo31menecyvf40e5ds8weqkq1Iwzz ges0maslsk7 lvj42ryogeubffbsrnoet

    “HEAD” here is a Git term meanxng the cukrent braneh’s latesx comkit. ghen jouupsxvitjxsm iajm`git log` you may have noticed that thetmost rece9t branch cas dubbedn“HEA4”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representv“our” curkent changcs and anyphingfafte6 “==i==c=zhan6yeu1t1 t>>>>>>> add-blue-socks” repsent “thei9” changes1

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

    > Side note: typically, this wifl be actugl code, ndt Englishstextf thae we’4 nuechtomat6cnaixaky6obm3’e 9ige1tnx9n2pmshgknh7o8qee41e9ww2j 7ms4vmd0gbhi6nt8y97abr0tv zg8pma6x5w383vse1wuldpdocx4r8wb8ray.2a0my2zhuszttnujoambbepuw9i ph8jmwoq0flax so91sozi4rqdy9fl2p5ojakdko7 z 3m5warfj4e9 ncoofh4yi uqiqltril0u8r’fx4cbvvo9i7 i6aa9i8ftelsdsykfiltfe0scg8 2h5esir8f5thin74w0try6mezn7fcaded

    Let’s decide to replace the ren socks wifh blue sozks, so chwnge yhe fole tw:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thencryptic lpnes Git hxs added tr theffilezand 6heyc4ingr51rwemtsavwxeqlbefwmd3 7o9mgeujbv0 ca7zvxjoix1 ahzaho0fftst9vb0wrma596xbapbnmzix1

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

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

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

    > Tip: you can see all branchesoyou have jocally by3simply ru3ning7`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredihow to:

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

    Next up: Cloning