Return to Video

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

  • 0:00 - 0:03
    To answer this question, let's think
    about what commits were present on
  • 0:03 - 0:06
    GitHub and in your local repository
    before and after git fetch.
  • 0:07 - 0:09
    When you cloned the repository,
  • 0:09 - 0:12
    the latest commit on it was Larry's
    commit adding the chili recipe, so
  • 0:12 - 0:15
    that also became the latest
    commit in your local repository.
  • 0:15 - 0:17
    Of course,
    there were other previous commits, but
  • 0:17 - 0:20
    I'm leaving them out here for
    the sake of space.
  • 0:20 - 0:22
    Now you made a commit
    adding a new spice, so
  • 0:22 - 0:26
    that commit is also present
    in your local repository.
  • 0:26 - 0:28
    And that's where your master branch is.
  • 0:28 - 0:32
    origin/master still points to
    the commit that was on the remote at
  • 0:32 - 0:33
    the time that you cloned.
  • 0:33 - 0:37
    After you cloned, Sarah added
    the no cumin commit on GitHub, but
  • 0:37 - 0:40
    your origin/master branch
    won't reflect that yet.
  • 0:40 - 0:43
    So, this is the state
    of master on GitHub.
  • 0:43 - 0:44
    Now, this was the state of
  • 0:44 - 0:47
    both repositories right
    before you ran git fetch.
  • 0:47 - 0:52
    So, if you ran git log origin/master,
    you should have seen that Larry's commit
  • 0:52 - 0:56
    adding the chili recipe was present,
    but your commit adding a new spice and
  • 0:56 - 1:00
    Sarah's commit removing cumin were not
    present on the origin/master branch.
  • 1:00 - 1:04
    If you run git status, you should have
    seen that your branch was ahead of
  • 1:04 - 1:06
    origin/master by one commit.
  • 1:06 - 1:11
    This makes sense because git log and git
    status both run without internet access.
  • 1:11 - 1:13
    Suppose you were somewhere
    without internet access when you
  • 1:13 - 1:14
    ran these commands.
  • 1:14 - 1:19
    Your local git repository would have
    no idea that the cumin commit existed.
  • 1:19 - 1:21
    So, of course, the cumin commit
    wouldn't be shown when you ran git
  • 1:21 - 1:23
    log origin/master.
  • 1:24 - 1:28
    And git status wouldn't know that your
    branches were actually out of sync.
  • 1:28 - 1:31
    It thinks that your
    branch is just ahead.
  • 1:31 - 1:35
    Now when you run git fetch,
    git fetches the no cumin commit and
  • 1:35 - 1:38
    updates the branch origin/master
    to point to that new commit.
  • 1:38 - 1:42
    Your local master still points at
    the new spice commit like it did before.
  • 1:42 - 1:46
    So at this point, you have a local
    copy of the no cumin commit saved, and
  • 1:46 - 1:48
    you can access it via git log.
  • 1:48 - 1:52
    If you run git log now,
    you'll see both the no cumin commit and
  • 1:52 - 1:54
    the chili commit.
  • 1:54 - 1:57
    You still won't see your new
    spice commit since that's only on
  • 1:57 - 1:58
    your local master branch.
  • 1:58 - 2:00
    Now, since both origin slash master and
  • 2:00 - 2:03
    master have one commit that
    is not present on the other,
  • 2:03 - 2:07
    git status will show that your branch
    is out of sync with origin/master.
Title:
Local Copies of Remote Branches Solution - How to Use Git and GitHub
Description:

more » « less
Video Language:
English
Team:
Udacity
Project:
UD775 - How to Use Git and GitHub
Duration:
02:08

English subtitles

Revisions Compare revisions