Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
When working with collaborators they might push a change to your remote branch while you are working on the same file locally, resulting in a conflict. You will learn to create, and then fix, a merge conflict.
Keywords for Conflict Resolution:
Close, Fix, and Resolve
You can use the Issue Title to close issues. Using the above keywords along with the issue number can be used to close issues via commit messages. More info can be found in the GitHub help documents.
-
0:00
Let's say we want to add additional changes to our add-readme branch
-
0:03
before merging our pull request into the master branch.
-
0:07
This is really simple.
-
0:08
All we need to do is make the changes we want in our text editor,
-
0:11
commit the changes, and push the branch.
-
0:14
In this video, however,
-
0:15
we're going to intentionally create a conflict by making our edits and
-
0:18
committing the changes on the GitHub website as well as on our local copy.
-
0:23
This will give you an idea of the editing abilities on GitHub.
-
0:25
When you're just getting started using Git and
-
0:28
GitHub, my suggestion is to not make any edits on the website.
-
0:32
Doing all of your work locally will help you avoid conflicts
-
0:34
like the one we're about to create.
-
0:36
If you're only pushing up changes from your local computer and
-
0:39
working by yourself, you'll always be in sync with the remote repository.
-
0:43
However, if you do start working with collaborators,
-
0:45
they might just push up a change to the remote branch while you're working on
-
0:48
the same file locally, resulting in a conflict.
-
0:51
This is a fairly common issue, and it's not the end of the world, but
-
0:54
it can be scary, so let's practice creating and fixing a merge conflict.
-
1:00
Okay, so I'm here in my code view and I want to change to the add-readme branch.
-
1:04
Let's say I want to add an image to my README.
-
1:07
I'll click into the README.md file and click the Edit button here.
-
1:14
So here's a little hack or a pro tip.
-
1:17
If I wanna add an image to a readme file,
-
1:20
the markdown syntax in the markdown cheat sheet will tell us how to do that.
-
1:24
But a little shortcut is I can go to Issues and
-
1:29
New Issue.
-
1:33
And if I have a file like I do here, then I can just drag and
-
1:40
drop it into the issue body and it creates this automatic URL.
-
1:45
Or it creates the Markdown syntax that we need.
-
1:48
So I'll do Preview.
-
1:51
Cool.
-
1:54
So I can copy and paste it back here
-
1:58
and I can preview the changes.
-
2:05
Awesome.
-
2:06
So the green shows what I've added and that looks good.
-
2:11
So I'll go back and edit my file.
-
2:13
I'll also want to adjust this typo here.
-
2:18
Files completed and then let's do a,
-
2:49
And cool, looks good.
-
2:51
So here I will add a commit messages and
-
2:58
I can just say update README.md
-
3:04
to add image and fix typo.
-
3:09
I can add an optional extended description, and then I can go ahead and
-
3:13
directly commit the changes to the add-readme branch by
-
3:17
clicking Commit changes here.
-
3:22
Back in the console, normally if we have any changes to a remote repository,
-
3:27
we would use the command git pull to pull in the remote changes.
-
3:31
As they say, always pull before you push.
-
3:34
But let's say I forgot that I had made the change on the remote repository, and
-
3:37
I'm gonna go ahead and add some information to my README here.
-
3:49
And I'll save.
-
3:50
So in the console, I'll run the commands.
-
3:55
Let's make sure I'm in the right branch.
-
4:01
I'm still in the add-readme branch, great.
-
4:03
And so I will add and commit my changes.
-
4:16
Cool.
-
4:17
And I'll go git push origin, add-readme.
-
4:34
Okay.
-
4:34
What's going on?
-
4:35
It said failed to push.
-
4:38
Updates were rejected because the remote contains work that you do
-
4:42
not have locally.
-
4:44
This is usually caused by another repository pushing to the same ref.
-
4:47
Okay, so that's right, I forgot to pull, right?
-
4:51
So now I type git pull origin add-readme.
-
5:04
And I get a new error message.
-
5:05
CONFLICT: merge conflict in README.md.
-
5:09
Automatic merge failed; fix conflicts and then commit the result.
-
5:13
Okay, so here we can refresh the text editor.
-
5:22
And we can see there's a bunch of stuff here.
-
5:28
It looks kind of scary but we'll get through it, I promise.
-
5:31
Okay, we can see there are a lot of errors or
-
5:33
conflict markers which show us where the conflict occurred.
-
5:36
There's an equals sign that separates the two versions.
-
5:40
On the top, the head is the most recent commit, and
-
5:43
the one I was trying to push up from my local computer.
-
5:46
And below the equals signs was the change that I made on GitHub.
-
5:50
I'll need to choose which to keep.
-
5:52
I wanna keep the one that has the image,
-
5:55
so I'll just have to delete all the rest of this here.
-
6:07
And all these conflict markers, and save.
-
6:11
And then back in our console,
-
6:17
we'll do a git status.
-
6:21
Cool, I'll do a git add.
-
6:24
git commit -m. We'll go, fixed
-
6:30
merge conflict,
-
6:35
and I'll go git push
-
6:40
origin add-readme.
-
6:52
Cool.
-
6:54
Now we'll go back to the Treehouse repository.
-
7:00
We'll go to the Pull Request.
-
7:05
You can see my commit history right here, updated README.md file to add
-
7:10
the image and fix the typo, added my profile locally.
-
7:14
And then another commit message where I fixed the merge conflict.
-
7:17
Also, if we go here, we can see this commit history.
-
7:21
Now that I've added our additional comments and fixed the commit,
-
7:24
let's go back to our pull request.
-
7:26
We can see the additional commits to the branch are shown here.
-
7:30
And let's take another look at the files changed view, too.
-
7:38
Commits, and the file's changed.
-
7:41
That's fine.
-
7:44
Okay, this looks good.
-
7:46
Now let's click Merge pull request and confirm the merge.
-
7:53
Confirm merge.
-
7:55
Pull request successfully merged and closed.
-
7:58
Woo hoo!
-
7:59
Congratulations.
-
8:00
You've completed your first pull request.
-
8:02
Since we won't be using the add-readme branch any longer,
-
8:05
we can delete the branch here.
-
8:08
If we revisit the issue page, we see that the add-readme issue is now closed.
-
8:13
Because we included fixes number one in our pull request body,
-
8:17
GitHub took care of closing that issue when the pull request was merged.
-
8:21
If we go to our profile, we'll see a green square on our contributions graph.
-
8:25
Great job.
-
8:27
Let's quickly review what we've done.
-
8:29
After we opened a pull request,
-
8:31
we made a change to the repository on the GitHub website.
-
8:34
Since we forgot to do a git-pull,
-
8:36
we made a change to the same file on our local computer and we created a conflict.
-
8:41
In the text editor, we deleted the lines we didn't want to keep and
-
8:44
then committed and pushed up to the remote repository on GitHub.
-
8:47
Problem solved.
-
8:49
In the next stage,
-
8:50
Kyle will show how to use these features to collaborate on a team.
You need to sign up for Treehouse in order to download course files.
Sign up