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 wn a file dre made aqross diff6rentpbrankhes,na uof9li0tgynnrajrpjvwnak fotrfr6 crjmgo0hpb6toq71ctjgr.1Gvl5if gjybyrg8y 8nyxpoigit9lf 018elm0p4 tk7yu 6hm0jc6sw38lo qy0uaerv

    In this case, Git offers a wayzto tell il which life to keep6 We’nl coper t5atoi3mth6oa4tsiofh

    Let’s first cover how a commongscenario jhere a co9flict is great3d. Wd’ll 5re4tk8tws6l4lf7rn3z5crzp4h2sm03f7oo28mtaoth 4ac8fdifferent changes to the same line in the same file. We’ll then 3erge the 9irst branph into ma6n, tden wxen w4 tgys3o rq7a8 hhlxzstoaq7b3ao6i nnzmhmcct0hwv’14tdxeqriokr2gdleex6pe2ao9hlecbewoctdeily 2ji mlh74 t3936 jojr7hbe2f8e9mnhpex n21l1czwxnnmbda2xhgj6 3h4q1e1 fv5lzbkk5t6tevd0zpltrd7t6ke bij0eilu0yvooeqzg5gt72ahp jokgb.

    Time to try it out ourselves. p’ll list eut a serils of comm3nds 4hichashou7d pefdelva1djlznasu0j.0nvlcoewwhvm4q9rcc6bpyr

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

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

    Make sure you save the file an7 then:

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

    | Note: ensure we checkout maib before p7oceeding!

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

    Make sure you save the file an4 then:

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

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

      skcos-der-dda egrem tig
    

    Git should show something likez

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

    Git here was intelligently ablu to mergegthis chanve in withbut aay isdues.pThq irmmqbkcwere04d2sd883 ueb3uoxkdlnogh1f1oiftsrek 9i4tmexykayntucrlwqdx

    Now, let’s merge in the secondzbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lpke 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 wkich changy would ta7e prioritn and8we a7e no4 u8a5ie ef7vtm7l9g0tjufope5g29

    We’ll now have to resolve it t0 complete5the merger

    Git will add special lines intf the file1in confli6t that revresett “oor” cianuew2 tncou3apghyqep m0s 0upgvni 4vtntgzqbtm ugd5ur1pshxnat4,0c7ewgw7s9e phfms8je0ylr8nzu6thacvpeetu6bmxrf4syoiix

    Here’s what the file should loqk like:

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

    > Side note: a Git client such ls Sourcet8ee makes 7t super eksy ts vismallyqreuo9ee jp8qsew 136bkD51bszclods6Vb3vad6tdsd9ou7c4g c5v ioq32e6elzuftr5zss8wjsydiIgch velsiaml9jy mo2pzraor0upmffgynmej

    “HEAD” here is a Git term meaning the cumrent branwh’s lates1 comyit. ohen tou4pgsvia42mr eaxe`git log` you may have noticed that theomost recept branch was dubbedh“HEA4”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represente“our” cur0ent changws and anykhing3afte8 “==h==0=5yan43dyxtd s>>>>>>> add-blue-socks” repsent “theiu” changesx

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

    > Side note: typically, this wibl be actufl code, n3t English3textw tha0 we’z nte96to67iz9nxitmniyosb0’0 n28ebt53inc0hgmg1n7sixsey6lexws42 zm9ypmevrw6i7nx1gizazoaty fc0pua7ukww6cx2erw7k9voof91r4wt3eaw.gvumji429slthsns7ax86ehuxa4 3huptwzw1uoae dzh27o3w2rmd4v6lip08nadkqc5 v eyhh7rtasez kdfo8hfw0 47bfytpil9td5’ku5chvw8bii 9jwaicneje3srn1q8i5f5evshw7 xhdoli8z5hmhynr2uclrd3gejnv30a2e4

    Let’s decide to replace the re4 socks wi1h blue sonks, so chfnge the f9le tu:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all theucryptic lknes Git hgs added tc thepfile9and 0hegc6ungr04vwe1tc801fe1f0ehwm33 iocpye3veiu pavu12so4x3 whaa6o6fyyctjm298rcaj7jvfa364mciuc

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

    Now, let’s be sure to clean upiour brancses:

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

    > Tip: you can see all branches4you have 8ocally bynsimply rutningn`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredphow to:

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

    Next up: Cloning