How do I compare contents of a file in two different branches in my Git repository?

Using git-diff  you can compare contents of a file in between two branches.

# Changes between
# the feature and the master branches
$ git diff feature master -- myfile.txt
# OR
$ git diff feature..master -- myfile.txt

Notice the difference between two dots (..) and three dots (...) when comparing a file in between branches:

# Changes that happened on
# the master branch since when
# the feature branch was started from it
$ git diff feature...master -- myfile.txt

You may also compare contents of different files in different branches by using a slightly different syntax:

# diff contents of myfile.txt
# from the feature branch with
# contents of yourfile.txt
# from the master branch
$ git diff feature:myfile.txt master:yourfile.txt

Check the Full Official Documentation for git-diff for more options.