35. Fetching changes

Goals

  • Learn how to pull changes from a remote repository.

Run

cd ../home
git fetch
git log --all

We are now in the home repository.

Result

$ cd ../home
$ git fetch
From /home/alex/githowto/repositories/work
   39a1e0f..71df43a  main       -> origin/main
$ git log --all --graph
* 71df43a 2023-11-28 | Changed README in original repo (origin/main, origin/HEAD) [Alexander Shvets]
* 39a1e0f 2023-11-28 | Renamed hello.html; moved style.css (HEAD -> main, origin/style) [Alexander Shvets]
* 23149b5 2023-11-28 | Included stylesheet into hello.html [Alexander Shvets]
* b9e6de1 2023-11-28 | Added css stylesheet [Alexander Shvets]
* 85c14e9 2023-11-28 | Added meta title [Alexander Shvets]
* ee16740 2023-11-28 | Added README [Alexander Shvets]
* 9288a33 2023-11-28 | Added copyright statement with email [Alexander Shvets]
* b7614c1 2023-11-28 | Added HTML header (tag: v1) [Alexander Shvets]
* 46afaff 2023-11-28 | Added standard HTML page tags (tag: v1-beta) [Alexander Shvets]
* 78433de 2023-11-28 | Added h1 tag [Alexander Shvets]
* 5836970 2023-11-28 | Initial commit [Alexander Shvets]

At the moment, the repository contains all the commits from the original repo; however, they aren't integrated into the local branches of the cloned repository.

You'll find the commit named "Changed README in original repo" in the history. Notice that the commit includes origin/main and origin/HEAD.

Now let's take a look at the "Renamed hello.html; moved style.css" commit. You'll see that the local main branch points to this very commit, not the new commit we've just fetched.

This brings us to the conclusion that the git fetch command will fetch new commits from the remote repo, but won't merge them into the local branches.

01 Check the README

We can show that the cloned README file has not been changed.

Run

cat README

Result

$ cat README
This is the Hello World example from the GitHowTo tutorial.

No changes, as you can see.