3

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?

Mureinik
  • 297,002
  • 52
  • 306
  • 350
Suraj Cheema
  • 103
  • 1
  • 7
  • 1
    After a `git fetch`, you will see messages from git as you change branches or use e.g. `git status` if your branch differs from the remote it's tracking. For example: `Your branch is behind 'origin/typescript' by 1 commit, and can be fast-forwarded.` is what I see right now. It's not clear whether that's what you're looking for, I would recommend trying it out. – jonrsharpe Apr 17 '20 at 11:22
  • Have a look at the long answer here: https://stackoverflow.com/questions/47675225/how-to-see-a-result-of-git-fetch You may use `git fetch -v` to see more output of your command. – YesThatIsMyName Apr 17 '20 at 11:27

3 Answers3

4

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
Mureinik
  • 297,002
  • 52
  • 306
  • 350
  • 2
    You can also cut-and-paste the two hash IDs: `git log 4f3d3b431..d82301acb` for instance, from the `master -> ...` line. Or, `git diff 4f3d3b431..d82301acb` will show you what changed here. @SurajCheema should note that this is what just got *fetched* just now; multiple `git fetch` operations over time, with no intervening update of your own branch names, will often result in `git log master..upstream/master` showing *more* than `git log ..` from the most recent fetch. – torek Apr 17 '20 at 11:40
  • Thank you! That was a very helpful answer. – Suraj Cheema May 01 '20 at 11:44
1

If the remote is called "origin" (you can see with git remote -v), you can check the changes of your master branch with the "origin" master branch with

git diff master origin/master

You can use all commands you want with the remote commit: log (you can see the history and highlight yours with --decorate, if your commit is in remote history), show, ...

eugenioperez
  • 627
  • 7
  • 15
0

This would definitely work,

git diff master origin/master

Whereas if you just want to see what files will be modified if you do a GIT PULL, do this:

git fetch && git diff HEAD @{u} --name-only

If you want to see all differences between your current version and the incoming version, including uncommitted local modifications,

git fetch && git diff @{u} --name-only

And,

git log --all --oneline --graph

will give you the change log for all branches E.g. output -

enter image description here

Nishan
  • 3,644
  • 1
  • 32
  • 41