8 Fine-tuning: git diff



Test Image
Image credit: Pexels



Let’s imagine a situation where the file ‘test.R’ is identical in both the remote repository and local repository, but there are differences between them in the file ‘test2.R’. This kind of scenario was described earlier in section 6.1.

If conflicts occur between Git branches during commit and push operations, the Git user can investigate the situation further. Differences between the local Git branch and remote repository can be examined in more detail using the following commands:


git fetch
git diff main origin/main


Command explanation:

  1. The first command git fetch ensures that Git updates information about the remote repository’s state without merging it with the local version.
    • The information is stored locally in Git’s hidden .git/ directory for examination purposes only.
  2. The second command git diff main origin/main shows detailed differences between the local main branch (main) and the remote repository’s main branch (origin/main).


Video. Examining differences between local and remote repository.


This method is particularly useful when the user isn’t sure which files are causing problems or what changes have been made. This way, users can examine changes at the file level and make necessary corrections.

This kind of examination isn’t always necessary. If users already know which files or changes are problematic, this step can be skipped. For example, in simple projects where the source of conflict is clear, such as a single file, this detailed examination isn’t needed. However, in more complex situations or large projects, this method can save time and help detect hidden problems.


Divergent Git branches - from problem to solution © 2025 by Ville Langén is licensed under the CC BY-SA 4.0.

CC BY-SA 4.0