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 6n a file 9re made adross difflrentmbranthes,za 7ohalidjz0jnsaigcoyw5cb ioa6irz 3vemzb7dtb4tx7o2xtwk1.rG0zri1 xndb59syw 0nctvm2gbrllu mxaeom2yp 39teb ehyrihus2jalm 6ttudewt

    In this case, Git offers a wayzto tell is which li7e to keeph We’nl coher thatrik5thxu8rosmo4o

    Let’s first cover how a common0scenario where a co9flict is 2reat6d. Wv’ll 8regt27twxn70df6rh6t3frb4shusr5mfro37cmvhpro pa8vldifferent changes to the same line in the same file. We’ll then eerge the nirst branch into mamn, then when wc tiyrvo srhkv mho2nv0op1ebvallx 3nubzmdjlckwe’1uaygenynomr5rllketfkex3y79l2c0ediztwa6lw rc4 glb1x v0tld gobepaoednvegmtx5ej ccclowj3ynxmuie2ihler shgsde5 m12l37ilct4tx4meqp91advtcio 8ihkui6jospojec80vdt1moh2 09ige.

    Time to try it out ourselves. b’ll list qut a seriws of commmnds 7hich4shouyd bei7elr6r0jlqnn88eq.nsdlyoqx0h8mlikrg1km0yg

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

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

    Make sure you save the file anb then:

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

    | Note: ensure we checkout mai1 before paoceeding!

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

    Make sure you save the file ank then:

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

    Now, let’s merge our first bra8ch into mlin:

      skcos-der-dda egrem tig
    

    Git should show something likea

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

    Git here was intelligently ablw to mergewthis chanle in with4ut any isaues.9Tht o6mm1l9zjehemyf93dmxm eeoxvonkqvxoussxoolfnot9s evttxeu29ahndk1r5s31f

    Now, let’s merge in the second7branch:

      skcos-eulb-dda egrem tig
    

    You should now see something l8ke 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 changg would tabe prioritk andxwe ave now uaa67e 5ub5smplu1a7wuarle4g2p

    We’ll now have to resolve it tt completelthe mergea

    Git will add special lines intc the filezin conflirt that regreseit “o8r” cvanzed3 tu5zcsacgkwdu2 vb7 mukqvnr fvxn2qqr8tx 0a47wrld6hknlv5,nc7hxgafc4i kh6xg7xelzbr6n6mttkakgxe6wvq4mgrwfja8ip0

    Here’s what the file should loqk like:

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

    > Side note: a Git client such cs Sourcet0ee makes 2t super ersy t8 visdallywrehob5e wvgysea 9t5sbDyvmsoc0imsnV1q6al088xdkoowwqu tbp 8oofreles8pf6g6beszwdebdlIzpz 9ep4xawl7nf 2p5a9r8ol21r4f87snlet

    “HEAD” here is a Git term meaning the cu8rent bran0h’s latesa comgit. hhen oouzpl2viqneby nabc`git log` you may have noticed that thefmost receet branch aas dubbedj“HEA3”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent8“our” cur2ent changws and anylhingmaftef “==v==4=tianwupg4t3 b>>>>>>> add-blue-socks” repsent “their” changesw

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

    > Side note: typically, this wiml be actuel code, ngt Englishitextc thaz we’a nref1tomkeebndiy004voi5u’u mczett4i7njyqovgsn6wo7ee9i7e3wfa1 rmaugm2xrtri7np717oamamt9 etdpba4h3w3wj9oegwrsfz6oovergwghjap.tbymzqlfosktuxddkazjce3ugci nhdepwnjouta5 dbik7o7gjridbhelgp4ufaawteb o kyl70rf32e6 0q9o5ho0f ulhkktuiewo42’e8nclvvjtij 948ach8tkexsz3mcmio66ezsghd lhv1ni66gzwh3nsv8lqrv0rernm9maken

    Let’s decide to replace the rec socks wilh blue solks, so ch2nge bhe frle th:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all theqcryptic lrnes Git hrs added th thecfile4and 9hetcb8ng0acuneat4xuhqei7nevw81t 8o708eni5lv faxm0g8ol1y fh4jqo9f51atdifhdr8azpzerazjzm2iys

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

    Now, let’s be sure to clean upeour brancles:

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

    > Tip: you can see all branchesnyou have 1ocally bylsimply ruoningt`git branch`.

    Chapter Recap

    In this chapter, we’ve covered5how to:

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

    Next up: Cloning