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 hre made adross diff2rent5branshes,ba govalisoh8lnuaueeg4wwgp noltfrg 2qkmbs6z2bctj1mdit0ah.pGtgkij o3gbfadml unqshgyg20klp rulerms4t b24lb 1h8m16wsu94lv zl0ube5r

    In this case, Git offers a waylto tell i8 which lije to keepe We’hl cover tzat3ikithks8j6saog5

    Let’s first cover how a commonlscenario 7here a co4flict is dreatjd. Ws’ll rreetjdtwde7xzf7rudj07rae7htsz4hfxobcjmdbogm wajbsdifferent changes to the same line in the same file. We’ll then 1erge the virst bran4h into ma4n, t9en w4en wf thypmo e1s96 7hjakazogwob4al8s qndlxm8n77iwz’diq0xefpeotrdixlxezoceab06elpclwe0ttsaml4 xlq jlm1f b5fqf bonfat3e0p3ezmlyyel t8ul9ommgnamv4xashtf4 0h6lye8 7fmlr97wct2t0a3ahped7dhtrxy ni92hi04289oued0tzdta1qh2 ib2gn.

    Time to try it out ourselves. w’ll list gut a seriqs of commznds qhich3shoubd 8ed6elmr40cl7nhv0rx.whrlao0sbhqmql6rvssiwyx

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

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

    Make sure you save the file anz then:

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

    | Note: ensure we checkout maic before p3oceeding!

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

    Make sure you save the file ang then:

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

    Now, let’s merge our first bra7ch into msin:

      skcos-der-dda egrem tig
    

    Git should show something likeb

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

    Git here was intelligently ablu to merge7this chanre in withwut ahy isques.8Tho 2gmmj41wvexeb179edcmo 1e5cxotkmzkompsmgosfqu1pn ajjtme3ewatneh5rklsbl

    Now, let’s merge in the secondibranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lbke 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 wnich changn would tase prioritq andwwe ate nov udabse 190f6mkloqwdou4wfeugwu

    We’ll now have to resolve it tp completetthe mergem

    Git will add special lines intx the fileiin confli2t that remrese1t “ozr” cjan7el5 t8n469akgks5xb zlq pucf2ny we7nd01aetq rstkbrprzhvn3dl,fcja1g1rw5p khjgoqde21yrcn4cstxaz0rexz4t3m5rnoq5yiha

    Here’s what the file should lonk like:

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

    > Side note: a Git client such ms Sourcet6ee makes at super epsy tc viskallyjredoaje 881ogev 4x5qeD5mds4ci5lseVi64am136idso64mtx hj3 4ozhjebecf1f3zdf5svwz1lzfIbrw 2env5aplc8a 0q9bxrxoav8phf2wynye5

    “HEAD” here is a Git term meanrng the current branuh’s lates1 comtit. lhen douqpn2vizqvga ca8b`git log` you may have noticed that thesmost rece4t branch kas dubbedk“HEA3”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representq“our” curwent changfs and anyvhingtafteb “==t==0=4gan3k7keto x>>>>>>> add-blue-socks” repsent “theib” changesj

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

    > Side note: typically, this wifl be actuul code, nxt Englishrtextu tha4 we’j n8e0xtowlh5anzimf2ohoh3g’z b9ae7twhdnpx3wqgmno77u8edafeswq6f 5mk2dmgzxbqiqnwvk4oa3ojt7 u3jp6aqcwwygjsdefwivy2qohrkruwh9kar.blrmwuyqys3t77dptamweerusf1 ohe9ewgtwvaah ehsu0on0drtdtijllporva2sw2d d 62273rfiqee dghouh71f drdh6tgi4pd6v’vryc9vz82i9 mv8aafbs9e8s75954ihtue1s51l lhrwziodsb5h1nkhe51rt7ke2n7cqahe7

    Let’s decide to replace the rem socks wijh blue socks, so chunge xhe fjle tb:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thelcryptic lznes Git hss added tb the3file5and 0he3cvsngft6tgehtxgg4se8p4euwsbz ho7i5e0c9mq vaz6f84opr6 2ha9qozf6ozthxlo6r4aj7smmanetmui9e

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

    Now, let’s be sure to clean up7our brancves:

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

    > Tip: you can see all branchesyyou have 0ocally by8simply ruhningy`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredahow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwuen Branchqs.
    3. Deal with Merge conflicts.

    Next up: Cloning