English subtitles

← Local Copies of Remote Branches Solution - How to Use Git and GitHub

Get Embed Code
6 Languages

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

  1. To answer this question, let's think
    about what commits were present on
  2. GitHub and in your local repository
    before and after git fetch.
  3. When you cloned the repository,
  4. the latest commit on it was Larry's
    commit adding the chili recipe, so
  5. that also became the latest
    commit in your local repository.
  6. Of course,
    there were other previous commits, but
  7. I'm leaving them out here for
    the sake of space.
  8. Now you made a commit
    adding a new spice, so
  9. that commit is also present
    in your local repository.
  10. And that's where your master branch is.
  11. origin/master still points to
    the commit that was on the remote at
  12. the time that you cloned.
  13. After you cloned, Sarah added
    the no cumin commit on GitHub, but
  14. your origin/master branch
    won't reflect that yet.
  15. So, this is the state
    of master on GitHub.
  16. Now, this was the state of
  17. both repositories right
    before you ran git fetch.
  18. So, if you ran git log origin/master,
    you should have seen that Larry's commit
  19. adding the chili recipe was present,
    but your commit adding a new spice and
  20. Sarah's commit removing cumin were not
    present on the origin/master branch.
  21. If you run git status, you should have
    seen that your branch was ahead of
  22. origin/master by one commit.
  23. This makes sense because git log and git
    status both run without internet access.
  24. Suppose you were somewhere
    without internet access when you
  25. ran these commands.
  26. Your local git repository would have
    no idea that the cumin commit existed.
  27. So, of course, the cumin commit
    wouldn't be shown when you ran git
  28. log origin/master.
  29. And git status wouldn't know that your
    branches were actually out of sync.
  30. It thinks that your
    branch is just ahead.
  31. Now when you run git fetch,
    git fetches the no cumin commit and
  32. updates the branch origin/master
    to point to that new commit.
  33. Your local master still points at
    the new spice commit like it did before.
  34. So at this point, you have a local
    copy of the no cumin commit saved, and
  35. you can access it via git log.
  36. If you run git log now,
    you'll see both the no cumin commit and
  37. the chili commit.
  38. You still won't see your new
    spice commit since that's only on
  39. your local master branch.
  40. Now, since both origin slash master and
  41. master have one commit that
    is not present on the other,
  42. git status will show that your branch
    is out of sync with origin/master.