How Can I See the Differences between Two Branches?

Better Stack Team
Updated on June 24, 2024

To see the differences between two branches in Git, you can use the git diff command followed by the names of the branches you want to compare. Here's how you can do it:

 
git diff <branch1> <branch2>

Replace <branch1> and <branch2> with the names of the branches you want to compare. This command will show the differences between the two branches.

For example, to see the differences between the main branch and a feature branch named feature/new-feature, you would run:

 
git diff main feature/new-feature

Viewing Differences with Color and Context:

You can also add options to git diff to display the differences with color highlighting and context lines. For example:

 
git diff --color-words --no-index <branch1> <branch2>

This command will display word-level differences with color highlighting.

Note:

  • If you want to compare the current branch with another branch, you can omit one of the branch names in the git diff command. For example, git diff main will compare the current branch with the main branch.
  • The git diff command can also be used to compare commits, tags, or specific files. You can specify commit hashes, tag names, or file paths instead of branch names.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github