YO WHAT IS UP.
Everybody this is Jason with dustups dot com and in this video we are going to learn how to handle merge
conflicts.
All right now merge conflicts happen when there are two developers working in the same codebase and
someone accidentally changes the same line of code that maybe somebody else was working on.
All right.
And then when those changes are committed up to get or get a hub it gets confusing it's like there's
changes on both sides on the same line.
I don't know what to do with it.
So we're going to go ahead and in this example we're going to create our own merge conflict and I'm
going to walk you through how to handle it.
So integrate it.
Go ahead and let's create a new repository.
All right and we're going to call this
let's just call this merge conflicts suck because they do.
I'm really good at creating these subconsciously by the way.
I have a real knack for it.
So anyways we've got our repo name merge conflicts suck and then go ahead and create the repository.
All right.
And then with your S-sh here go ahead and get this copy to your clipboard.
All right.
And then what I want you to do is open up your terminal.
OK.
I'm going to minimize this for now.
Get this in the center of the screen.
Let's enlarge this.
So how do I merge conflicts happen here so to simulate this what we're going to do is I'm going to create
two folders and then clone this repository into each of those folders and what these folders are going
to represent is one coder's computer.
And like coater B's computer.
All right.
So let's do this.
So in my home directory here I'm just going to create a directory make der Butsy merge conflict.
If I could split right merge conflict.
All right.
So we created a directory there.
Actually no we're not going to call this a merge conflict and to call it coater A because these are
people right we're dealing with people and then we're going to make another directory and we're going
to call this quarter B.
This is going to be my buddy.
We're both going to start on this really cool project together.
All right.
So I've got these two folders.
All right.
So Khoder A.
I will say that me comes into here and let's see I have to change directory in here so CD coater a.
So now I'm in the directory and we're going to clone the repo that we just created.
So get clone and then paste the URL that we copied from.
So now we're cloning our Ribault merge conflicts suck.
Go ahead and throw in a password if you need to.
And cool.
It says that we've got this report now.
Remember the repository that we've just created is empty.
So why don't we go ahead and add a file to this.
Now be mindful that we created a folder called coater a and we cloned the directory into this folder.
So we actually if we list this out we have to now step into our folder repo that would just cloned.
All right.
So in here there's nothing.
So let's go ahead and create a file.
So we're just going to call this mangy ass.
Ok cool.
So I'm going to use a command here.
I'm going to open up the Adam text editor and I just got kind of a little hot key to open this up.
You can just fall longer opening up in your own text editor.
I'm going to do Adam dash period to open up the directory that I'm in.
So it's going to launch Adam here for me.
And what we're going to do is we're going to create just two simple lines of code create some variables.
So Varnum will say is equal to 50.
All right.
And then let's do a bar.
Truth is going to be.
Hello world.
I guess we can cap that.
All right.
Hello world.
Sweet.
So me being coater a I just initiated this first project.
I created the repo.
So what I'm going to do now is I'm going to go ahead and I'm going to push this up.
So let me just clear up some space here.
So if we are to do it get status.
You can see that we have the untracked file that we just created.
So I'm going to go ahead and add it to be tracked.
Let's go ahead and committed and we'll add a message first commit are right.
And then we'll go ahead and push this.
Now normally we always want to do a poll before we do the push but I'm the guy who created the ripple
right.
So I'm the first one pushing so I can simply just do a good push origin master K we're working on the
master branch right now.
All right so enter my fancy password.
All right.
So now that has been pushed over to bitbucket I mean now that's been pushed over to get hub.
So if we come into here and we refresh this you can see now that we've got our file in here.
Ok going to minimize this.
All right so now I'm going to you know message my buddy and say Yo dude I've got the repo created.
Go ahead and clone it onto your own computer.
And it's like do.
That sounds great.
So I'm going to open up another tab here.
I'm going to enter CD to go back to my home directory and remember we need to go into the coater B directory.
OK.
This is going to be my buddy.
And this represents a different computer OK.
This is his computer at his house.
All right.
And there's nothing in here.
So I'm going to go ahead and clone the repo again.
And I've still got it copied to my clipboard so I'm going to paste it and hit enter.
All right.
Put in my fancy password and boom there it is.
So if we list this out you can see we've got a repo on here.
Let's go ahead and dive into the directory list down and we've got the javascript file on here.
So again what I'm going to do is I'm on coater B's computer.
I'm in a different directory and so I'm going to open up the same file here.
So I'm going to use my text editor open this up in Adam.
So we're going to have coater be over here on the right and coater A is going to be Orisha on the left.
And you can see the different file names here at the top.
OK.
So coater been my buddy.
He's like oh man I see a bug in this code like we've got an error here.
So we're going to do.
Hello.
Flat earth because we are not on the world right.
Like this is a flat earth.
So he's like Cool I've got these changes saved.
I'm going to go ahead and push this up.
So I'm in the coater be my buddy's computer here.
And what we're going to do is we're going to do a guest status and we can see that we've bonafied the
javascript file right we've changed it.
All right.
Let me go ahead and type in clear.
Just to give us some more space.
And so my buddy he fixed this bug.
And so he's like all right I'm going to go ahead and add this.
I'm going to do a commit here and I'm just going to fix the bug.
And then we're going to go ahead and because we're good developers we're going to pull in Master into
our branch here.
So give Paul Orjan master.
Now what do you think's going to happen here.
So coater a I mean I officially initially created the code and my buddy cloned it and then he made a
change to it.
Now he's pushing it so if he does get Paul Orjan master let me show you what it's going to say here
it says already up to date.
Now why is that.
Well I haven't made Corail rehear hasn't made any new pushes since coater be my buddy over here is done
with his stuff and is now pushing so good is going to say hey you've already cloned this.
There hasn't been any changes from anybody else aside.
So everything's Square it's all up to date.
Go ahead and push.
And so I'm going to get push origin and master.
So now my buddy just pushes up his branch and everything pushes successfully.
And then as I'm looking at my code coater a me I'm looking at this and I'm like oh dude shoot I've got
an error in here and I haven't even talked to my other buddy to see if he's made changes or pushed and
I haven't even checked myself.
All right.
If we opened up this and we refreshed it you can see that the last commit here was two minutes ago and
the commit message has changed.
So let's say that I'm diving into my project again.
I haven't checked to see if any changes were made.
I haven't talked to anybody.
And I was like OK I got to fix this bug.
And we're going to say hello Flader.
So I fixed the bug.
I'm feeling really good about this.
So in my terminal I'm going to switch back over to the coder a directory.
Let's clear this right.
And if we do our guest status shows that we made we modify the change here so get at it and get it and
then fix that cray cray bug can edit my message and I am just an amazing developer so what am I going
to do.
I'm going to pull master into my branch and let me tell you what's going on here.
So let me I guess just hit enter on this and then type in my password and it says do it.
There's there's a conflict here like What the heck's going on and what what good is screaming at us
about it says I have to.
To commits here two pushes and line two in the same file has changed and I don't know which ones which
ones.
This one says right here.
Is it supposed to be.
Hello flat-Earth.
Or is it supposed to be hello flat earth like the change you just made.
Now in here you can see that Adam our text editor that kind of has some built in terminal tools I guess
you could say.
And it's asking me which one is correct.
Is it hello flat earth or is it.
Hello flat earth like on your local you have one thing on your local machine and up in a remote repo
or run hub it's different.
And I'm just confused and I don't know which one it is.
Instead of solving this through our text editor I'm going to show you how to do this through the terminal.
So what I'm going to do.
I'm just going to finish reading this.
It says that there is a conflict merge conflict in our main file and it says that it's failed and it
has fixed these conflicts and then commit the result.
All right so we're going to have to commit this again after we fix it.
So what we want to do is type in the command.
Let me just clean this up.
We're going to type in a good merge tool.
All one word.
Hit enter.
And you can see over in the text editor on my local it's created some backup files.
That's ok don't worry about it.
And then it says in our terminal just hit return to start the merge resolution tool.
So I'm going to hit enter here.
Awesome.
So this is the get merge tool here and it shows right here you see how this says main local.
This is what I changed it here on my local machine on my computer.
And then it says but on the remote it's something different and it doesn't know which one to do.
Well it gives us a couple of options how to handle this down here in the bottom right corner.
You can see there's a dropdown that gives us some options.
We can either choose the left side the right side we can say Oh both of them are right.
Start with the side first or say you know what neither of these are right.
So instead of choosing a side I'm going to say that I called my buddy and said bro you screwed everything
up like we've got merge conflicts here what were you thinking.
And we're going to talk it out and we're going to work things out we're going to still be friends with
Seascale on the weekends and we're going to come to a conclusion that none of these answers are right.
So what you can do is down here at the bottom we realize that we're both wrong.
And it's just Hellcats you know it wasn't about Earth being flat or round.
It was really just about the cats.
So what we can do now is go ahead and hit command s or control s to save it.
And in the background I mean minimizers you can see that it changed my local over to yellow cats.
All right we fixed it.
Pretty cool stuff.
Now check this out.
So we save this.
You can go ahead and hit command cue or just close out of it.
And then let's open up our terminal again.
And so we fixed the resolution.
We resolved it.
Now if I list out the items in here you'll see that I've got an extra file in here.
This mangy stock a ridge.
This is a backup that get made for us of this file.
Just in case we needed to look back on it.
Well we don't need it.
So why don't we go ahead and remove it so remove main are just on a ridge.
OK.
And you can see that it removed it from my local as well over here.
All right.
So remember it said that after we fix this Myrt conflict we have to commit again.
So if we do a guest status it says change is to be committed.
We still have to commit this file here OK because we changed it we updated it going to clear this give
us some room so good can it dash em.
My buddy and I are still friends.
All right.
Cool.
So I'm glad we work that out.
All right so we've got that and then we can go ahead and push this now and get push or.
M.
All right let's put in our password and everything is good.
It's all up to date now.
Now check this out.
So we have fixed the merge conflict.
I can call it my buddy and says dude we finally get this worked out.
The master branch is up to date.
Go ahead and pull that so he can simply just do a good pull Orjan master.
This is coater B.
This is my buddy.
This is the other computer.
And watch this code over here watch what happens when he pulls from Master.
Now we're going to do this for on the password.
And there you have it.
He his his local branch now is fully up to date with master.
So that is merge conflicts.
In a nutshell and the best thing that you can do to prevent these merge conflicts is communicate talk
to the other guys girls the developers make sure that everybody knows who's working on what features
in what files and just keep that communication open and just make sure you're not in the same files
touch touching the same lines of code that can get really really messy and complex sometimes.
And that is a wrap for this section.
Let's move on.