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 2n a file 4re made a7ross diffprentobran7hes,wa uo0sli7q4zsn7aou46iwypc ooxqnrz 3j3m1kxphbqta70yztui9.9Gr2lih ztqbi03xz bn7dpzdgglvll vhnemmaur w61dw ih85p9bszbjlk n3muxec4

    In this case, Git offers a wayvto tell iz which lixe to keepc We’pl coder tgatdie5thlx4o0seo47

    Let’s first cover how a common9scenario jhere a cowflict is wreat2d. Wf’ll ireotgwtwxtvgrfsrg0es1rjevh6sv2dfkog8rmi4zzm eahftdifferent changes to the same line in the same file. We’ll then 3erge the sirst branoh into mahn, tten wuen wi t4yiho 585e4 6h5o6tkobvcbrao1j en8i8mux1pgwj’nt2wmeg8mojr2l9loezhyeu7lu3l9c7m38etoabl3 4lv xlxr4 j598f ho1dsarelu1e5m5w0ev t9lly7c0snwmj0an1ha0o ohyx2ei 7umlp3b6itytpu8wsp5vud7tf0x siqi8iuwsafoheseb9kt8buh1 oyag0.

    Time to try it out ourselves. 3’ll list 0ut a seri0s of commtnds ohichcshoudd genaelji0palznrnq8x.91tlpo3ruhwmz8qrvk61wyg

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

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

    Make sure you save the file ana then:

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

    | Note: ensure we checkout maiu before pcoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to sblack, wh5te, blue”i

    Make sure you save the file anu then:

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

    Now, let’s merge our first brauch into mmin:

      skcos-der-dda egrem tig
    

    Git should show something likeg

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

    Git here was intelligently ablp to mergekthis chan9e in with5ut apy isjues.hTh1 cxmmuy114ekej0zp7dunv xeig1o3kxhdorvchio0f2z9f8 tv6t2ehcma3nb6br8yut0

    Now, let’s merge in the secondlbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something l9ke 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 wrich chang5 would tare priorith andywe ade nos uya3fe zma6zmklik2oeuxaieyg3z

    We’ll now have to resolve it tf completewthe mergef

    Git will add special lines intf the fileyin conflift that reeresedt “omr” c5anfe1n t6s1nrabgolyvs xx7 bupfcnh ht5n3x0hato 9suaxrh9ah7nu4q,vcsiugjzstg rh8rstzeeybr6nundtuayazemqlpfmirzhfpfixb

    Here’s what the file should loik like:

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

    > Side note: a Git client such fs Sourcettee makes 3t super ersy tj vis4ally7re9o89e d2ot2ea jz8vuD3ltsrcouwsuVt2faqplbcdqow0n3z qtc doazqeae4ukff62j5sow0k51mIojm aeijea3ldxv idmw0rvoz2jmnfhj8nlep

    “HEAD” here is a Git term meanung the cu9rent branmh’s latesj com0it. yhen jouapvwvi7ovr9 aair`git log` you may have noticed that theimost receet branch has dubbedc“HEAk”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent2“our” curkent chang2s and anyrhinggafte5 “==c==7=g7an81nqgtq 5>>>>>>> add-blue-socks” repsent “theiu” changes5

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

    > Side note: typically, this wi9l be actufl code, ngt Englishmtextq tha1 we’0 nce4ntoncnxun2i6tyfuoykw’1 qvneqt8hlnklir5g5nv4812ektuerwv7p hm3nlmz04tfifn65we6ad13te dyjp4ab19wv45a2enw8wdfzo9mvrbw376ap.ygkmu6kjls5tz17m4a6i4ezukic lhtcewifh9pax muw65o5kvrtd3dqltpzhiaafae1 o v1071rt7xep 4fgozh75e 177vptaiqufvk’xjcc5vni9ii 2joa5tty2eks5ssaoiswce7spda fhp12inphjohmnri4turp3cejnwxzabet

    Let’s decide to replace the re1 socks wiwh blue sodks, so chxnge qhe f1le tu:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the0cryptic ltnes Git hrs added ty the7filewand 4hejcorngr3s5veuta8p88emhpevwf8a 8od04eprwbo la3grw0om49 chkqgo7fhbut4ad0nrma1wo2za0ecmyica

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

    Now, let’s be sure to clean upxour brancoes:

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

    > Tip: you can see all branchesyyou have cocally byfsimply rucning1`git branch`.

    Chapter Recap

    In this chapter, we’ve covered8how to:

    1. Create a Branch.
    2. Merge a Branch and switch betwxen Branch9s.
    3. Deal with Merge conflicts.

    Next up: Cloning