-
Title:
New - Keeping a Fork Up-To-Date
-
Description:
-
While you're making a contribution to
the create your own adventure story, you
-
may find that your pull request can't
be merged because of merge conflicts.
-
Here's how that could happen and
how you could fix it.
-
Suppose you fork the original
repository on GitHub, clone your fork,
-
then make a change in a new branch,
and push that change to your fork.
-
In the meantime, someone else changes
the original repository on GitHub.
-
If there are merge conflicts
between their change and
-
your change, then your pull request will
not be able to be automatically merged.
-
Since there's no way to resolve
merge conflicts on the GitHub site,
-
you'll need to resolve the conflicts
within the clone on your computer.
-
To do that, you'll need to get the
conflicting changes from the original
-
repository into your local repository,
which you can do by adding a remote.
-
Recall that you already have
a remote set up called origin that
-
points to your fork.
-
But you'll still need to add a remote
that points to the original repository.
-
And many people name
this remote upstream.
-
Adding and fetching the upstream
remote will add branches like
-
upstream/master into
your local repository, so
-
that you can merge the upstream
branch with your local branch.
-
For example, I created a pull request
to add an option of stop, drop, and
-
roll to a page of the story
where there was a fire.
-
In the meantime, though, another
change was made to the same file to
-
add an option to turn on
the chocolate sprinkler.
-
That change conflicts with mine, so
-
I need to resolve the conflicts
before my pull request can be merged.
-
So in this diagram, this is the commit
adding the chocolate sprinkler, and
-
also this one.
-
And my change was to add a stop,
drop, and roll option.
-
These commits were the same
in all the versions.
-
Since I created my change in
a separate branch, I want to
-
make my master branch the same as
the master in the original repository.
-
So, I'll run git pull upstream/master
to update my master branch to
-
the latest commit from
the original repository.
-
Then I'll merge the master branch
into my changed branch, and
-
I'll push both the changed branch and
the master branch to my fork.
-
I didn't need to push the master branch,
but I thought it might be nice.
-
Now since this whole process only
contains commands that you've
-
already learned, I want you to try
doing this on your own before I
-
demonstrate how to do
it on the command line.
-
As a reminder,
the steps you'll need to carry out are,
-
first, add the original repository
as a remote in your clone.
-
Next pull the master branch from
the original repository into your
-
clone's master.
-
Merge the master branch into
your change branch locally.
-
And resolve any merge conflicts.
-
And finally,
push your change branch to your fork,
-
which will automatically
update your pull request.
-
If you run into trouble,
-
I'll demonstrate how to carry out
this process in the solution.
-
If you didn't run into this problem
because your pull request was
-
merged without conflicts,
I encourage you to get some practice by
-
making a new change and
then not making a pull request for it.
-
Then you can wait for
someone else to make a change and
-
then get some practice
bringing your fork up to date.
-
Even if there are no merge conflicts,
you can still get practice merging.
-
Once you've finished this process,
check this box