English subtitles

← New - Keeping a Fork Up-To-Date

Get Embed Code
5 Languages

Showing Revision 3 created 05/24/2016 by Udacity Robot.

  1. While you're making a contribution to
    the create your own adventure story, you
  2. may find that your pull request can't
    be merged because of merge conflicts.
  3. Here's how that could happen and
    how you could fix it.
  4. Suppose you fork the original
    repository on GitHub, clone your fork,
  5. then make a change in a new branch,
    and push that change to your fork.
  6. In the meantime, someone else changes
    the original repository on GitHub.
  7. If there are merge conflicts
    between their change and
  8. your change, then your pull request will
    not be able to be automatically merged.
  9. Since there's no way to resolve
    merge conflicts on the GitHub site,
  10. you'll need to resolve the conflicts
    within the clone on your computer.
  11. To do that, you'll need to get the
    conflicting changes from the original
  12. repository into your local repository,
    which you can do by adding a remote.
  13. Recall that you already have
    a remote set up called origin that
  14. points to your fork.
  15. But you'll still need to add a remote
    that points to the original repository.
  16. And many people name
    this remote upstream.
  17. Adding and fetching the upstream
    remote will add branches like
  18. upstream/master into
    your local repository, so
  19. that you can merge the upstream
    branch with your local branch.
  20. For example, I created a pull request
    to add an option of stop, drop, and
  21. roll to a page of the story
    where there was a fire.
  22. In the meantime, though, another
    change was made to the same file to
  23. add an option to turn on
    the chocolate sprinkler.
  24. That change conflicts with mine, so
  25. I need to resolve the conflicts
    before my pull request can be merged.
  26. So in this diagram, this is the commit
    adding the chocolate sprinkler, and
  27. also this one.
  28. And my change was to add a stop,
    drop, and roll option.
  29. These commits were the same
    in all the versions.
  30. Since I created my change in
    a separate branch, I want to
  31. make my master branch the same as
    the master in the original repository.
  32. So, I'll run git pull upstream/master
    to update my master branch to
  33. the latest commit from
    the original repository.
  34. Then I'll merge the master branch
    into my changed branch, and
  35. I'll push both the changed branch and
    the master branch to my fork.
  36. I didn't need to push the master branch,
    but I thought it might be nice.
  37. Now since this whole process only
    contains commands that you've
  38. already learned, I want you to try
    doing this on your own before I
  39. demonstrate how to do
    it on the command line.
  40. As a reminder,
    the steps you'll need to carry out are,
  41. first, add the original repository
    as a remote in your clone.
  42. Next pull the master branch from
    the original repository into your
  43. clone's master.
  44. Merge the master branch into
    your change branch locally.
  45. And resolve any merge conflicts.
  46. And finally,
    push your change branch to your fork,
  47. which will automatically
    update your pull request.
  48. If you run into trouble,
  49. I'll demonstrate how to carry out
    this process in the solution.
  50. If you didn't run into this problem
    because your pull request was
  51. merged without conflicts,
    I encourage you to get some practice by
  52. making a new change and
    then not making a pull request for it.
  53. Then you can wait for
    someone else to make a change and
  54. then get some practice
    bringing your fork up to date.
  55. Even if there are no merge conflicts,
    you can still get practice merging.
  56. Once you've finished this process,
    check this box