How to resolve merge conflicts in Git

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi there it's Peter here again the guy who hates Tomatoes but loves front-end development in today's video you will learn how to resolve simple merge conflicts in kit but before we do that don't forget to smash to like subscribe to the channel so you don't miss all the other get tutorials to be able to merge two branches together we will firstly create two branches we'll make two changes in each of them and then we see where the conflicts appear and how to resolve it okay so you I want you to be clear of what we're working with so for now we have a git branch only master and well we will create two branches and we'll make two changes in each I'll speed up through this process because it should be quite straightforward by now we are adding two names to his branch so the content txt gets two names in his branch and will save it as his changes and in my branch I will add two colors and save it as comet with the message of my colors or my changes now we can try to merge his branch into my branch let's say I'm working on a feature and your colleague is working on another feature and you want to bring his feature into yours and continue working in your branch mackay so we will try to merge his branch into my branch and to do that we simply need to check out the branch you want to merge into so we are currently on a my branch which is correct and we want to merge his branch ok so remember you need to be checked out on the branch you want to merge into and then you merge the branch of the changes you want to bring in ok so if we do that then you will definitely get a conflict because we both we've edited the lines 4 and 5 of the content txt and then Gator doesn't know how to automatically resolve this conflict because we both touch the same file in the same lines if we touch different lines then it could easily merge it automatically but because we've edited the same file same line we gonna get conflict and here it is the the famous conflict that everyone hates and in this tutorial you will learn how to resolve it without any headaches so we are being notified by gate that the content txt is the issue and he couldn't automatically resolve it and we need to resolve the conflicts manually and commit the result okay so if you freak out at this moment and decide to quit the merge call ambulance or policemen or firefighters whatever your approaches then you can still revert back to merge so abort the merge and the command is get a merge abort okay that will repair the merge cancel everything and you are back where you were before merging these two branches together so if you freak out the abode will always get you out of trouble now we try to be brief and we will merge so we can go back to this and merge again and this time we'll try to resolve it we won't be aborting we will be resolving okay so we've got couple options here the first one is accept the current change which is the change in your branch or in this case my branch then the accept incoming change which would only take the changes the incoming changes which is the John and Michael or we can accept both which would keep the file and write all these four lines into it or we can compare the changes so here is the change visually on the Left we are adding yellow white on the right side we are adding John and Michael so this is the two files side-by-side and it's up to us how we want to resolve it I will first accept the current change which would bring the two colors if I revert it accept incoming change John and Michael comes in he can undo it and if we accept both we see all four lines written okay so this is the three options you have and it's up to you how you resolve it based on your coat we will save the file with the changes we are happy with and at that moment we are still in the merge process okay so if we look at git status you see that we have unmerged pass which means that this file is still not resolved we need to mark it as result and to do that we need to use the git add and the file name ok so if we go he get add and content dot txt or git add dot or period it will do the same thing that tells get that that file is resolved and now we can commit it and we can simply get commit and give it a clear message merged his branch now the changes are merged git status should be happy and get a lock should show us that we have the merged his branch commits successfully completed and that's how you resolve conflicts in git I know it can be frustrating when you merging and having conflicts but only practice makes you perfect so don't be afraid to create a simple demo like this where you changing files just few lines get familiar with the commands get familiar with how via scored marks it for you which changes is the incoming which is the current one and that's how you will become more comfortable with merging bigger changes bigger files bigger projects and there is no shortcut for it so don't be afraid even if you think you experienced just break it down create a simple demo like this and practice until you are a hundred percent comfortable if you've enjoyed this video don't forget to semester like subscribe to the channel for more videos like this and let me know in the comments what would you like me to cover next until next time epic coding bye you
Info
Channel: Ihatetomatoes
Views: 271,209
Rating: undefined out of 5
Keywords:
Id: xNVM5UxlFSA
Channel Id: undefined
Length: 6min 36sec (396 seconds)
Published: Tue Apr 21 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.