Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

github
git flow

How to compare a branch in GitHub

Sheza Munir

GitHub is one of the most commonly used version control and collaboration softwares in the development community.

Branches

Branches allow users to develop in an isolated environment without affecting the rest of the repository. Each repository has a main branch, and all other branches come from existing branches. To merge the work on two or more branches, you must use a pull request.

Compare branch

You can set a branch to be compared to another (usually main) branch. This allows you to view the changes as they appear in the main files once the changes are merged. When you open a pull request. you compare two branches that may be merged (if there are no conflicts).

  • Go to ‘Pull requests’ and click on ‘New pull request’.
widget
  • Here you may select branches to compare.
widget
  • Lines that are added are highlighted with a green background and are preceded by a + sign.
  • Lines that are removed are highlighted with a red background and are preceded by a - sign.

Viewing options

There are different ways you can view the differences in the branches being compared.

  1. Unified view: The unified view shows updated and changed content in a linear manner. Each changed block of code is shown right after the previous, unchanged block.
  2. Split view: The split view shows the old and new content side-by-die in a parallel manner.
  3. Rich diff view: This view shows a preview of how the code will look once merged into the repository.
  4. Source view: This view is similar to the rich diff view, but without the formatting.

RELATED TAGS

github
git flow

CONTRIBUTOR

Sheza Munir
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring