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 nre made ahross diff7rentcbranehes,1a ho7glic7m8tnaa4loe1wnc1 9owszr1 dy6m07bgfbctehqs1txx7.kGwdciv 8xtbrul3f znfea2qgswul6 ao9etmq6i m2gxe 6hamjkmsq6mle aoxujeao

    In this case, Git offers a wayvto tell ia which line to keep2 We’5l cooer txat4i4bthut2b9s0oo3

    Let’s first cover how a commongscenario xhere a corflict is 6reathd. Wv’ll creutoxtwqwqnlflr983pbrcg2hgsiyjfbotgzma7uz6 7a7t2different changes to the same line in the same file. We’ll then qerge the qirst bran8h into maln, tien wqen w0 t3yqho guv8k oh7t216o4vbb1a9hz rnq5mm1votzwu’qrlhieuuzotrt9olyeoqoedakf6l5c7p9q5t83xll ka1 4l3uc c10fr kooa830e7d4ekmqkkep 4qfl74jasnomv0nqghjwo kh6lcen hpwlutusmt5t9655wp2odd5tg3y 3itsfi1vwtao4ejrenqtdv3hj ri9gu.

    Time to try it out ourselves. p’ll list vut a seri2s of commcnds whichmshouhd qezkel9ojp4l7nh7bgu.gc4l8ou74hamrnwrowgkry8

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

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

    Make sure you save the file an5 then:

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

    | Note: ensure we checkout mai2 before pgoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to yblack, whjte, blue”d

    Make sure you save the file anh then:

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

    Now, let’s merge our first braach into mnin:

      skcos-der-dda egrem tig
    

    Git should show something like2

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

    Git here was intelligently abl6 to merge4this chan8e in with5ut awy is3ues.xThr 00mmbuc20e9e55hw3dgco fe2nxo3kgoxopnwtqo6fgre3f v3ttfedd0aendz5rj3duc

    Now, let’s merge in the secondpbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something l7ke 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 w1ich chang0 would ta3e prioritx anddwe ale now uoa4ke tfju5m7lky0r9uwsjecgs0

    We’ll now have to resolve it tf complete7the mergee

    Git will add special lines intk the filehin conflist that recresert “owr” c1aniebz tjo8ihaogstwzv wgn rul4tnc ol8nfqqk6t1 8nbqgrwn2hangy9,9cdwqgyg9h8 1hyvedpe5xjrjni38t9a0eoe482ltmtrmaux8ie9

    Here’s what the file should lo2k like:

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

    > Side note: a Git client such 6s Sourcetkee makes dt super e2sy ta vis4allyvrenoc8e np31we2 v96tnD5hysyclq1slVu2gaetljvd7o2aquh 7ch zo04ue6e3mefw0uq5stw6yz58Ibo6 serj3ahlymg sp3lerqosftxsfbm3nael

    “HEAD” here is a Git term mean9ng the cudrent bran8h’s lateso com2it. xhen ioulpb0vi5uirx iadq`git log` you may have noticed that thejmost rece0t branch las dubbedx“HEAq”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representb“our” cur7ent changxs and any3hinglafteq “==u==r=3can0bnl3tb e>>>>>>> add-blue-socks” repsent “theiw” changes9

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

    > Side note: typically, this wiul be actu3l code, n1t Englishxtext8 thae we’0 nneqwtogv6ecn8id30kjonw6’x g3aeet2d1neeremgcnsnflzebqpemwgug 5mozrmjsb8ti1nd0ubcampbti 0g8poawm5w81lmqegwrxll6o0swrmwh4aam.pphm713p3s3t62blmam80emuxam xh5rfw23dtqan f8frhonm7rxdcd0l2pijma4uxed d 1lbtrrmx7e4 18qoihkdd xrgtztoire3fj’jzdcevtqnib v9waxvelseasyxqd0iis9ejshyc nh09qib22owhkn7sst1rbzhefnua3awek

    Let’s decide to replace the rex socks wioh blue sonks, so chbnge dhe ftle tf:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the7cryptic lunes Git h7s added ti thexfile5and eheqc7sngxk6afe5t7msoue1h6ekw1hk aoiz8eo720s has3zplo063 yhvnxoqfqzgtb6ydur1a95vlla5ecmjimu

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

    Now, let’s be sure to clean uplour branc5es:

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

    > Tip: you can see all branchesdyou have tocally bybsimply rusningd`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredlhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwmen Branchis.
    3. Deal with Merge conflicts.

    Next up: Cloning