How can I see the differences between two branches?

I have two branches: branch_1 and branch_2.

How can I see the differences between them?


Solution 1:

You want to use git diff.

git diff [<options>] <commit>..​<commit> [--] [<path>…​]

Where <commit> is your branch name, the hash of a commit or a shorthand symbolic reference

For instance git diff abc123…def567 or git diff HEAD..origin/master

That will produce the diff between the tips of the two branches. If you'd prefer to find the diff from their common ancestor to test, you can use three dots instead of two:

git diff <commit>...<commit>

And if you just want to check which files differ, not how the content differs, use --name-only:

git diff --name-only <commit>..​<commit>

Solution 2:

It's very simple. You just go to one branch (e.g. main is your branch).

Run the command

git checkout main
git diff branch2