Search code examples
gitgit-fetch

Where to see the changes with "git fetch"?


I am just curious as to how to view changes after typing "git fetch".

My research has told me that it allows you to see if your local repository is up to date with the remote repository without changing your code in the local repository. However, where will I be able to view the changes after typing the command?

An example could be my colleague commits a change and I type the command to see if my local repository is up-to-date, what will it display and where will it be displayed?


Solution

  • git fetch fetches changes from a remote repository and stores them locally. Whenever you check out a tracking branch, you should see a message about how it differs from the branch its tracking. E.g.:

    mureinik@computer ~/src/git/commons-lang [somebranch] $ git fetch upstream
    remote: Enumerating objects: 763, done.
    remote: Counting objects: 100% (763/763), done.
    remote: Compressing objects: 100% (31/31), done.
    remote: Total 1881 (delta 721), reused 747 (delta 713), pack-reused 1118
    Receiving objects: 100% (1881/1881), 717.42 KiB | 758.00 KiB/s, done.
    Resolving deltas: 100% (936/936), completed with 236 local objects.
    From https://github.com/apache/commons-lang
       4f3d3b431..d82301acb  master     -> upstream/master
       09043bfa6..e389ce1ed  release    -> upstream/release
     * [new tag]             commons-lang-3.10-RC1 -> commons-lang-3.10-RC1
     * [new tag]             rel/commons-lang-3.10 -> rel/commons-lang-3.10
    mureinik@computer ~/src/git/commons-lang [somebranch] $ git checkout master
    Your branch is behind 'upstream/master' by 147 commits, and can be fast-forwarded.
      (use "git pull" to update your local branch)
    

    You could also explicitly see the differences with git log:

    mureinik@computer ~/src/git/commons-lang [master] $ git log master..upstream/master