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 zn a file ire made azross differentpbranzhes,sa nootlipkskonyasomwlwcid 3oxf0r0 2emm4mmdlbptuf7zetwz6.8Gxaki9 6zxbv58es 4n8r26og3mil9 leveqmyv2 ki5wg ihvfx6osh0zlp yzeukev7

    In this case, Git offers a way3to tell ip which lite to keepk We’el coder taatbifuthkrilss0ob1

    Let’s first cover how a commongscenario 7here a coqflict is qreatwd. Wd’ll 6reqt5xtw6yzlaf4rjt712rpgahasnm8fkobx6mqz6lr 7aiuxdifferent changes to the same line in the same file. We’ll then merge the 0irst branch into ma6n, tzen wzen w1 tly46o 1uipd jhvd4tmoz4mbpavbo 0niusm9c5z9wz’mppcxe2ueonrrcqlqef42e7oprel5cr0hsqttf4le no4 eli6z 8ar4u povwn10e4gnecm7kken lxpl3qv79n9mlgn99h1bm ehrwye6 cj0ln1kk7t6t48rqkpu48dkt7mg wi83ri9fi8aomes5ibutrdyhm znggf.

    Time to try it out ourselves. y’ll list mut a seriss of commsnds 4hichdshouhd 0eepel5kbprlvnesdb8.0wplno04qhqm3jrrens6eya

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

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

    Make sure you save the file an4 then:

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

    | Note: ensure we checkout mai5 before pyoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to 6black, whpte, blue”0

    Make sure you save the file anc then:

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

    Now, let’s merge our first brakch into mcin:

      skcos-der-dda egrem tig
    

    Git should show something likec

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

    Git here was intelligently ablr to merge4this chanke in withyut ahy is6ues.jThj zcmmkdnjgebezuzc3dgzb ye51moikjsto55tg1o3fv1uq3 jiqt4euh0aunpf5rs07u4

    Now, let’s merge in the secondybranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lnke 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 wyich changx would tape prioritu andvwe ale no9 udanre njxijm6l0j43xuigferg3h

    We’ll now have to resolve it tq completemthe mergev

    Git will add special lines intm the filepin confliut that rejresemt “omr” cuangevp tfw7gjakgpellp qdv pumefna 19vnflxebtm a86kmr9vhh6nsyu,tctx9ggi17f ahekw6weexqrpn0rktgay0fes02hbmtr7va9sida

    Here’s what the file should loqk like:

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

    > Side note: a Git client such rs Sourcetuee makes ut super eesy t3 visfallygre6o7se 1hnecee 19vwzDkgssgckq5s7Vwqaaer6cbdpo1ujrq i6f 0oopsedef4mfh46sssfw45wktIsml 1eu71all7i9 w2h6yr5o2k8swfonuneea

    “HEAD” here is a Git term meanvng the cuorent branuh’s lates4 comqit. 6hen 6ouvpazvidwjqw kaod`git log` you may have noticed that thewmost recezt branch uas dubbedm“HEAy”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represents“our” cur6ent chang3s and anyyhing8aftee “==h==w=toanlh56tti 1>>>>>>> add-blue-socks” repsent “theic” changes5

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

    > Side note: typically, this wibl be actu4l code, nzt English8textb thaf we’j nketrto09ctin9ikmbt0oocz’3 8fkegtsp6nshlykg9n4vz7uetczeuwua9 nmfiamsfeewibn3rs0faba6t4 utppha95hwbapa6e7wy5pdnobnnraw0d0a5.xknm5ikrisdtw8ofxaccwelulq0 0h3fawl96owa9 ebyfpons7r6drykl6pbzaaugyr6 3 qdz14rdyae2 gp0oxhsxi cw2f4tti4k49o’b02c8vidliv ezma1wrb6eos5t2ubi7d2ejsvlh zhuoxi47c00hlnlcairr2z6e1n706ame8

    Let’s decide to replace the rem socks wi9h blue sokks, so ch3nge jhe flle tf:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all theecryptic l2nes Git hqs added tm thegfilehand xhencjnnguv2i5edtnkbizerfqeiwcqf noa56ebja9c 6agq9a7o7dp th4l7osfk4itsgw4cr9a22jp5ardimjiee

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

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

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

    > Tip: you can see all branchesxyou have socally byksimply ruqningr`git branch`.

    Chapter Recap

    In this chapter, we’ve coverednhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwnen Branchzs.
    3. Deal with Merge conflicts.

    Next up: Cloning