So in the last video, the pull request that Stevie generated was able to be automatically merged in
with a single button click, right?
We didn't have to do any merging locally on our machine.
It was all done in GitHub and then we just pulled down the changes.
But that only happens sometimes where the merge can be done automatically, just like any merge in git.
There's always a potential for conflicts.
So in this video I want to show you how you can resolve conflicts when merging a pull request.
Okay.
So we need to first start by making a pull request that will generate a conflict.
And to do that and to do things relatively speedily.
Hopefully, I'm going to start by doing a tiny change as Stevie.
So here we are as Stevie.
I'm going to just I don't know.
Well, let's change the title here of the entire Web page.
So we'll imagine we're doing some big task.
We're working on a feature branch, but really we're just going to change the heading.
So let's make a feature branch as Stevie.
We'll call this.
We make this a bit larger.
How about get let's see we're on main let's do get switch dash see because we're not going to work on
main and then we'll call this new heading.
So switch to a new branch, new heading, and now we can do some really basic work like change the heading
here.
Where is that?
Instead of an H one.
I'm going to give it a class of display one, which is just part of bootstrap.
And let's see what it looks like.
There it is.
And then I'm going to change the text to B.
I don't know.
Hey yo world.
Or how about actually, this is coming from Stevie?
How about just back, back, back, back?
Is that how you spell that?
I don't know.
Whatever noise my chickens make, it's like a.
Most of the time.
All right, so that's Stevie's change.
So Stevie adds and commits this to the branch.
So get add index, get commit change.
Heading to black bark.
All right, so now we can push that up or Stevie can push this branch get push origin new heading up
to GitHub.
Then simultaneously, I'm not going to go through the whole workflow of making a PR as Colt.
I'm just going to do some changes on the index directly on the main branch, which normally we should
be consistent.
And if we're going to enforce pull requests, I guess I'm the the owner of this repo so I can do whatever
I want.
But normally you follow some rules.
You're not going to have two sets of rules.
You're going to ask everyone to use powers to merge changes in.
But just to demo this faster and not lose your attention, I will directly edit the file on GitHub as
Colt.
Right.
So I can just edit a file and make it commit on the main branch.
So I'm going to edit this instead of saying hello world.
Where's that heading?
Right here it is instead of Hello World.
I'll do hello there everyone and maybe a bunch of exclamation points then I'm going to save that.
Well, not really save it, but I'm going to make a new commit.
So update index.
Sure, that's fine.
Commit directly to the main branch.
Here we go.
So now the main branch has changed and Stevie has a branch that was pushed up.
This is still kind of a trivial, silly way of of creating a conflict.
But there should be a conflict now where if I try and make a pull request as Stevie.
I'll take a look.
Here's my new heading branch.
Let's make a pull request.
Oh can't automatically merge.
Don't worry though, you can still create the pull request, so hopefully you see why we can't automatically
merge.
There's a conflict.
Just like if we tried to merge these on our machine with git merge.
It's the exact same mechanic.
So if I want to make a pull request to change the heading to bok bok I am a chicken and I changed the
heading to say bok buck.
I hope you like it.
So I have a message.
I'll create that pull request.
From New heading to Main.
And we see that there are conflicts that can be resolved.
So the way that our repo is set up, anybody who's a collaborator currently can resolve the conflicts
right and merge a PR.
Once that's resolved, I'm going to do it as colts, though, not as Stevie.
That's a more typical workflow is somebody submits the PR and then it needs to be reviewed.
So I'm going to go back to Colt's workspace and then we see there's a new PR.
Here it is.
And if I want to merge this in, unfortunately it's not as simple as clicking a button so I can do a
couple of things.
If I click the Resolve Conflicts button, it actually gives me an option to do this in the browser,
which I haven't really done before.
And this actually, for this example, is super easy to do it that way because it's just a single line
that we're keeping or combining.
But rather than doing it in the browser, I'm going to show you the good old fashioned way of doing
it that you would do if you had a bunch of files.
This is just one conflict in a single file, but in the real world you may run into conflicts across
a bunch of files.
Hopefully not too many, but still it might be easier to resolve them on your own machine so we can
click this view command line instructions and it tells us exactly how to do this on the command line.
So first we need to bring the changes in so we can fetch origin.
So we'll do that on my machine as Colt.
Get fetch origin.
All right.
So now we have this new branch reference, this remote tracking branch, to make this larger again.
Oh, well, that didn't work.
Try that one more time.
Here we are.
You can see Origin's new heading.
So the instructions.
Now, tell me to check out new heading there using the checkout command on the git or the github website.
They don't use get switched yet, which is the newer way of doing it.
So we could do this.
We're saying make me a new branch called new heading and have it track origin slash new heading or the
easier option is just to get switch new dash heading and it will do that for us as we've seen.
So now that I've done that, I can see here I should have bok bok showing up in the heading and I do
I have Steve's changes.
I am currently checking out, I'm switching or I have switched to that new heading branch that Steve
pushed up.
So now I need to merge in the main branch.
So this approach is switch to the new branch, the feature branch and merge main in to the feature branch,
resolve the conflicts there.
So just test things out and make sure it works.
And then when we're ready, we're going to switch over to Main and merge new heading in.
All right, so let's try that get merge main.
This is the main branch.
We know that there's likely going to be a conflict, although I think I am missing the latest changes
from Main.
Yeah, it's up to date because I didn't poll down.
So let's switch to Main.
I'll show you what I mean.
Get Switch Main.
Remember that I updated on Main on GitHub.
I changed the heading and it actually tells me that your main branch is behind origin slash main.
So we'll do a git pull origin main.
Now we have the latest changes on Main.
Now I can go back to new heading.
And then I can merge main.
So get merge the new main branch that we have.
It's not new, but the latest version, the latest work merge that into this new heading branch.
Now we have the conflict.
So now I can resolve the conflict here.
So maybe I want both.
Maybe I want to h one class equals display one from Stevie.
And then I want, I don't know, all these exclamation points.
How about Bok?
Bok, everyone like that.
So let's see what that looks like.
Let's refresh.
Okay, great.
So now we need to add and commit the changes.
So get add index and we'll just do a useless commit message like resolve conflicts.
So now we've merged the changes in, but we're just on the new heading branch.
So we've made it.
We know for sure that the current version of Master or Main works, when we merged it in with the changes
on new heading, we resolve the conflicts.
Now we can switch back to Main.
And then we can merge in that new heading branch that we already resolved the conflicts on, which is
exactly what they ask us to do or tell us to do on GitHub.
So go back to Main and then merge in new heading, which already has the conflicts resolved.
So we shouldn't get new conflicts.
Now this dash dash no f f, that's an indicator that we're telling git merge to not fast forward if
it detects that it can because when we do a fast forward instead of making a merge commit as we've seen,
it will just move the branch pointer to some new commit.
Right?
It just moves forward and sometimes we want to prevent that from happening, especially when we want
to preserve or maintain our specific branch.
We want to make it clear that there was a branch merged in here.
Just to have that history, you don't have to do this part, but it's just what GitHub recommends.
So we could just copy the entire line.
We're merging new heading into Main OC.
So see, I'm now going to put a commit here instead of just a fast forward, I'm putting a merge commit
in because I said no, fast forward.
All right, and now we just push it up to master get push origin main.
I said master again we're using main get push origin main.
Oh, right.
So now if I refresh this page, it automatically just I didn't I didn't refresh but it automatically
detects successfully merge this PR and it's closed now and you can delete that new heading branch if
you want.
Sure.
Let's delete it.
We can also restore it if needed.
And now we merged a PR in that had a conflict and the same process would apply if there was one conflict
or tons and tons of conflicts.
We make a request and then resolve the conflicts following the instructions.
Basically pull that code down or fetch it, check it out or switch to the new feature branch merge master
or main in resolve conflicts add and commit then switch back to master or main merge in the now conflict
less branch and then push that up.
Okay, so now the last thing to do is as STB, go and get the latest version right of the main branch.
We don't have that as Stevie, so we just need to pull down.
We'll switch to Main.
We can remove that branch now new heading so get branch dash dx new heading.
And now get pull origin man we'll get the latest changes from man and there's not a whole lot that we
got but if we type get log we see OC we got the resolving of the conflict merge that branch in my work
was merged in so now our latest version of the main branch says buck back everyone and we can take a
look at it right here and there we are.
So we successfully merged a PR in that had a conflict OC.