GIT Merge & Resolve Merge Conflict | How to merge & resolve merge conflict

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video we are going to learn how to do git merge with vs code and we will also see how to resolve merge conflict as well so as you can see in my GitHub for this test project I have this main branch and this main branch has these three files hello test and test two and then there is a readme file as well and then if you click over here it should show all the available branches so I have one more branch which is feature one as well so if you notice over here I have test and Test 2 file whereas in my feature Branch if I go to feature branch I have test 3 as well so I have another branch which has some code changes which has a new file test three so how do I get this file into main branch to get this file into main branch I need to merge this feature one branch to my main branch let's see how we can do that in vs code so let's open our project NBS code and as you can see even in my local I do not have test3.html file in my main branch I am on my main branch right now and I do not have test three five so how do I merge feature Branch into main branch for that let's go to the source control Tab and then click on these three dots and then click on this branch and then merge branch when you click on this merge Branch it will ask you from which branch you want to merge into your main branch so I want to merge from feature one branch but I don't want to merge it from my local feature one branch I want to merge it from the remote feature one branch so there is this origin slash feature one which means that it will merge it from the remote feature one branch if you want to merge it from your local in that case you should check out to feature one branch first and make sure that you have latest code by doing the git pull but we can simply do this as well origin slash feature one which will merge feature One Branch from remote in my local so let's let's click on it and there we go we have changes from feature one branch into my local main branch so if I go to Explorer tab you can see test3.html is there and if you go to Source control it will say sync changes it means that I have those changes in my local only because if I go to my GitHub website and if I just go to main branch I would still not see test3.html file because I have just merged it in my local but not in the remote so to push my changes to remote I'll just do sync changes click on OK and this should push my changes to my remote as well so if I just refresh the page I would see test3.html over here as well so now that you have seen how to merge your changes let's see how we can resolve git conflict git conflict occur when you have done changes in the same file as somebody else has done so let's take this test3.html itself and let's do some changes in this file so I can just edit this file and I will say this is my change from main branch it's climate changes commit these changes and this file has been updated now now let's say I am working on feature branch and I still have the old copy of the test3.html which did not had changes from mean Branch now if I do changes in this test3.html and then try to merge main branch into my feature Branch then I'll get git conflict because in my feature Branch also we have done changes in the same line so git conflict occur when you have done changes in the same line as somebody else has done in some other branch which you are planning to merge into your branch so let's see so in our source control as you can see we're already getting the sync changes option for main branch because we have done some changes in the test 3 file so we can do so that's good to go and now let's go to feature branch and do some changes so to check out to feature Branch you have to click on these three options click on checkout 2. and then go to feature one branch now I'm back in my feature one branch and now if you see in test3.html I still have the old copy of test C dot HTML because feature Branch does not know that test3.html is updated in the mean Branch so let's say I will update this line and say this is change from feature Branch save it and now let's enter our commit message changed test three dot HTML and commit and then push these changes to remote now I want to merge main branch into feature one branch so how do we do that go to this three dots and go to branch and Munch branch and we want to merge main branch so we can either do origin main which will merge it from the remote or in this case we can do mean as well because we know that we have the latest copy of main branch because we did sync changes so let's do this one so let's click over here and now as you can see we are getting some merge conflict so this is very simple as you can see over here it says that in head like in the current change this is the change so since we are in feature Branch this is the current change which we have this is changed from feature one branch and then in the incoming change which is coming from Main Branch it's a this is the change from Main Branch so now you have multiple options as you can see we have accept current change we have accept incoming change we have except both changes and we can compare changes so if you do accept current change it will accept this one and it will remove the other line so something like this or if you do accept incoming changes it will remove everything else and accept the incoming change in our case let's say we want to accept both changes we want change from feature branch and we want change from Main Branch as well so accept both changes and there we go we have resolved our merge conflict now vs code has already given some commit message as well so all we have to do is just click on this plus icon to Stage this file and then commit it and then just sync these changes and we have resolved our merge conflict so if I go to remote and go to code you should see the latest changes in the test three dot HTML file in your remote repository as well this is it with this video thank you so much for watching bye
Info
Channel: Harsivo Edu
Views: 5,465
Rating: undefined out of 5
Keywords: git, git tutorial, git merge conflict, merge conflicts in git, resolve merge conflicts git vscode, git vscode, git vscode tutorial, vscode resolve merge conflicts, vscode merge conflicts, vscode merge branch
Id: orAjM58JSGI
Channel Id: undefined
Length: 6min 52sec (412 seconds)
Published: Wed Aug 02 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.