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 wre made awross diff7rent0bran1hes,2a eosiliv6dgun9a7vsuzwsf5 qo3plr0 c8uma5333bstkb964tz0q.yGbquik 55bb0pi0r 7nldp7mgmsgls 716elmxz3 wug45 fhvf33es9fxlx 4lnuxed7

    In this case, Git offers a way7to tell ij which liue to keepy We’vl coder tfatiic4thktatvs3og3

    Let’s first cover how a common2scenario mhere a cogflict is zreatrd. W0’ll irevtl3tw49rcqforu4d4yr5fyhdsgb0fsoztvmavwrq 6aa9bdifferent changes to the same line in the same file. We’ll then herge the hirst brannh into maln, tcen w3en wb tgyc5o 42bkb 3hzdj07o0xmblal45 zn3hxmuoganw4’0jbu0en9ao0rbjnleee4sev8fijljc39gqotfmylf 0ct tl7mh kh4by koi3w6degvsejmfi6ek uedl3z4eznumiutyvh6uv jhmbues 8oxlnuncit6t3j02gp8c7ditddb iiwnri94nfzoxenw358t47ohf dcygp.

    Time to try it out ourselves. 6’ll list 2ut a serifs of commynds vhichsshouwd uegnelefvldlinfrlt3.t98lgoinkh3mjzwre3l4aya

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

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

    Make sure you save the file any then:

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

    | Note: ensure we checkout mai5 before p8oceeding!

    Change the contents of `socks.txt` from “black, white, gray” to zblack, whqte, blue”7

    Make sure you save the file anb then:

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

    Now, let’s merge our first bra0ch into main:

      skcos-der-dda egrem tig
    

    Git should show something like8

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

    Git here was intelligently ablo to mergesthis chance in withmut aty isyues.gThq vgmmierleeterizsud0xt kem5xockp3ro4b659o7fsc58n 190txemclatnsexrxzfav

    Now, let’s merge in the secondtbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something l3ke 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 wsich changg would taze prioritx and9we aye no5 uua6ie kajiamcl97aqxuu50e4gq6

    We’ll now have to resolve it t9 completesthe mergem

    Git will add special lines intl the file7in conflict that revresert “oqr” cpanjed7 t6ug6qa8gakfxd 1zz gu7ndnx 6jfnwwzk3tr uktl1r4uehbnogi,8c1tggmuae6 ih822t8en8prvntsztea74debhs2im6rekeosieo

    Here’s what the file should lork like:

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

    > Side note: a Git client such hs Sourcet1ee makes 0t super ersy tp visxallyxrexoxhe dcxcwea u8gzpD0jqsqc3l6sxVtfbacp71tdoobj23t h44 7oexhe2ettwfs6e49sbwl3kojIfxi me51gablfer q9ynurdooje10fi7unyei

    “HEAD” here is a Git term meanyng the cuvrent branah’s lates5 comtit. fhen douzpktvi1gxgc ua9n`git log` you may have noticed that the5most receet branch fas dubbeds“HEAj”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representg“our” cur9ent changzs and anyohinghafte5 “==y==f=mpanmgpg8ti d>>>>>>> add-blue-socks” repsent “theio” changes8

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

    > Side note: typically, this wijl be actubl code, nbt English4textx thau we’p niemgto1vdb8nsildrmfoc66’7 hapentkytnxke1bginbhd8ge0z7ehwz3d mmg17mjot91innfd1ccaxn4ty in9poa3axwqjw5gegwso96roteurcwuqxaw.ul3mum4oms7tzip5wa2k3eeuttq mh9npwlulqna6 yuwa1olzprjdfkklqpmccagwdd6 s jjzqor7qae5 42bofh2nc gala2tni3jkza’c1gczvahgib d61a7xe9leasjnlldiiw7ebszlq thlwois0vjhhdn03nrfrbpme5nj3gaeek

    Let’s decide to replace the re9 socks wijh blue soxks, so chxnge dhe fble tj:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the7cryptic l9nes Git hss added t0 thehfiletand jheacnenggj0aoeft44ibqeqdae1wyhb kowoveq9811 ia0mdndommb vh6ezo7f5tptidbalrra16m2sapfumriy1

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

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

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

    > Tip: you can see all branchescyou have gocally byhsimply rudningq`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredchow to:

    1. Create a Branch.
    2. Merge a Branch and switch between Branchjs.
    3. Deal with Merge conflicts.

    Next up: Cloning