Differentiating two branches in GitHub can be done by comparing them to identify differences in commits, files, or content. Here’s how you can do it:
1. Using GitHub’s Web Interface
- Navigate to the repository on GitHub.
- Go to the “Pull Requests” or “Code” tab.
- Use the “Compare & pull request” button or the branch comparison feature:
- Select the base branch (e.g.,
main
). - Select the compare branch (e.g.,
feature-branch
). - GitHub will display differences in commits, changed files, and content.
- Select the base branch (e.g.,
2. Using the Command Line
You can use git diff
to compare branches locally:
- Show Differences in Code:
- Run
git diff branch1 branch2
to see line-by-line differences.
- Run
- Show Differences in Commits:
- Run
git log branch1..branch2
to see commits inbranch2
that are not inbranch1
.
- Run
- Show Files That Differ:
- Run
git diff --name-only branch1 branch2
to list files that have changed between the two branches.
- Run
3. Using Visual Tools
- Tools like GitHub Desktop, GitKraken, or Sourcetree provide a graphical interface for comparing branches.
4. Via GitHub Pull Requests
Create a pull request from one branch into another:
- Go to the repository’s “Pull Requests” tab.
- Start a new pull request, selecting the branches for comparison.
- GitHub will generate a comparison view showing commits and file changes.
Tips:
- Always ensure your local branches are up-to-date before comparing.
- Use branch comparison to understand progress, merge conflicts, or changes in collaborative projects.