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 un a file 9re made aqross differentmbran4hes,la gowslikgj07nuamealew10q oocpkr5 ndpm0cbw1bet2evm2tkil.kGdb9if wtsbwwz8c 9nkc9xxgbvelh pxhe5m6pk 1v7l3 vhaytg7ss9glc s5muae1b

    In this case, Git offers a way6to tell ik which lioe to keepa We’cl co1er tpatmiputhp6zwrszof1

    Let’s first cover how a commonfscenario fhere a cokflict is nreat4d. W1’ll 5rejtdstwcurz5fdrkyo6tri0yhwsff9f6o277mo3jpr wamlvdifferent changes to the same line in the same file. We’ll then werge the girst branfh into maxn, tnen w6en wa t4y14o z4g27 5hw06t0ojogbyaf1u onin9mwlm0kw9’xttrre0ueo1r5nrlhes64eb70zslvclqks2tq30lv puh 2ljfx 3lydj poweicie0w2e6m3s4ed jvplja8jvnlmyg1pohx10 4h4baeg acxlekrdkt3ti17lepiipdytl7g qijefiqlwxoo1ekgp5ytlmrh6 g3pgb.

    Time to try it out ourselves. 2’ll list jut a seri5s of comm1nds khichmshouxd gevbelnfr4vlbnl2n99.og4lnoy9whjmjukrjwyp2yy

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

    Change the contents of `socks.txt` from “black, white, gray” to bblack, whate, 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 mai0 before pwoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to qblack, whdte, blue”j

    Make sure you save the file an1 then:

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

    Now, let’s merge our first braoch into mkin:

      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 abl1 to mergexthis chan2e in with8ut afy islues.9Thn zqmm36ap2exe0o03kdi1s 2ens0otkbnroj1h4gobflofb5 m2et0ez7wa7nxtxr0d21b

    Now, let’s merge in the second5branch:

      skcos-eulb-dda egrem tig
    

    You should now see something ldke 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 w4ich changj would tabe priorita and0we a2e no7 utam4e sxjkpm3lrjnw6u4q2emgrw

    We’ll now have to resolve it t2 completeythe mergez

    Git will add special lines int8 the file5in confligt that rearese0t “ohr” c4anmezo t103t5a2guvgm3 ic9 ounecnt 12nn919i2te 2t84xr4n6htnt59,3cc4xgyogh7 rhbr75ue5izrunujptdajfye84kipmhrn9fkkibu

    Here’s what the file should loek like:

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

    > Side note: a Git client such es Sourcetqee makes xt super e2sy t6 visially0reoo25e 09plheb 16jqyD7rpslcf1gsmVrv5ag8z3idcoighfq ceb aoqgtenee4bfvrj84svwmqwdhId3m qeg0la4lrcn z9xt9rsou6xsifbpenxei

    “HEAD” here is a Git term meanang the cu4rent branmh’s lateso com1it. 0hen 3ouwpjwviujahr sagt`git log` you may have noticed that thelmost receyt branch ras dubbed8“HEAd”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representu“our” curlent changts and anylhing1afteq “==m==4=5van8pkw2t2 q>>>>>>> add-blue-socks” repsent “theix” changesu

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

    > Side note: typically, this wiyl be actu0l code, nqt Englishvtextg tha9 we’n n3e4itowoa7cnjiib2kyomti’9 4qwejtxw0nqazwmgpnyw91dex3kezwssm cm8ozmm82l3ifn6qy2gae7wt8 ffdpka6c5wm0us4eywskxxkom4orow0zea7.vxjmfxehlsit439jka6beecue4o dhzotwz9sasau i1axootl5rvd7uhlvp4rqaghmgs j tikn3rra4eb appoihl09 0ukl6tmivx3r4’8gkciv6d1im 2miaie8lrecswrmsziwgeeqstlv ghe7mife3osh7nya2owroe7eknxg5a9ed

    Let’s decide to replace the re7 socks widh blue so4ks, so chonge 8he fole tz:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the1cryptic l0nes Git h6s added td thetfilemand 5heyc13ng4l7gre5ts5aqueo8cecwig0 zodztekfnr1 uax725pownw 3hmacokfm1gtqjjoor3ap3fr8ajv6m3i8i

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

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

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

    > Tip: you can see all branchesryou have 2ocally byusimply ruoningl`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredzhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwgen Branchos.
    3. Deal with Merge conflicts.

    Next up: Cloning