Fetching Changes

Goals

  • Learn how to pull changes from a remote repository.

Execute:

  1. cd ../cloned_hello
  2. git fetch
  3. git hist --all

NOTE: Now in the cloned_hello repo

Output:

  1. $ git fetch
  2. From /Users/jim/Downloads/git_tutorial/work/hello
  3. e0cc19e..b39ac69 master -> origin/master
  4. $ git hist --all
  5. * b39ac69 2020-06-20 | Changed README in original repo (origin/master, origin/HEAD) [Jim Weirich]
  6. * e0cc19e 2020-06-20 | Updated Rakefile (HEAD -> master, origin/greet) [Jim Weirich]
  7. * 046088a 2020-06-20 | Hello uses Greeter [Jim Weirich]
  8. * 3db0ffe 2020-06-20 | Added greeter class [Jim Weirich]
  9. * 8d90176 2020-06-20 | Added README [Jim Weirich]
  10. * 5aec14d 2020-06-20 | Added a Rakefile. [Jim Weirich]
  11. * 721b979 2020-06-20 | Moved hello.rb to lib [Jim Weirich]
  12. * 907a445 2020-06-20 | Add an author/email comment [Jim Weirich]
  13. * 4254c94 2020-06-20 | Added a comment (tag: v1) [Jim Weirich]
  14. * c8b3af1 2020-06-20 | Added a default value (tag: v1-beta) [Jim Weirich]
  15. * 30c2cd4 2020-06-20 | Using ARGV [Jim Weirich]
  16. * 4445720 2020-06-20 | First Commit [Jim Weirich]

At this point the repository has all the commits from the original repository, but they are not integrated into the cloned repository’s local branches.

Find the “Changed README in original repo” commit in the history above. Notice that the commit includes “origin/master” and “origin/HEAD”.

Now look at the “Updated Rakefile” commit. You will see that the local master branch points to this commit, not to the new commit that we just fetched.

The upshot of this is that the “git fetch” command will fetch new commits from the remote repository, but it will not merge these commits into the local branches.

Check the README

We can demonstrate that the cloned README is unchanged.

Execute:

  1. cat README

Output:

  1. $ cat README
  2. This is the Hello World example from the git tutorial.

See, no changes.