0
0
Gitdevops~20 mins

git diff between branches - Mini Project: Build & Apply

Choose your learning style9 modes available
Compare Changes Between Git Branches Using git diff
📖 Scenario: You are working on a software project using Git. You have two branches: main and feature. You want to see what changes have been made in the feature branch compared to main before merging.
🎯 Goal: Learn how to use the git diff command to compare differences between two branches.
📋 What You'll Learn
Have a Git repository with two branches named main and feature
Use git diff to compare branches
Understand how to specify branch names in git diff
💡 Why This Matters
🌍 Real World
Developers often work on separate branches to add features or fix bugs. Comparing branches helps review what changes will be merged.
💼 Career
Knowing how to compare branches with <code>git diff</code> is essential for code reviews and collaboration in software development teams.
Progress0 / 4 steps
1
Create two branches main and feature
Create a Git branch called main and another branch called feature.
Git
Need a hint?

Use git branch branch_name to create a branch.

2
Add a file and commit changes on main branch
Switch to the main branch, create a file named app.txt with the text Main branch content, add it to Git, and commit with the message Initial commit on main.
Git
Need a hint?

Use git checkout main to switch branches. Use echo to create file content.

3
Make a change on the feature branch
Switch to the feature branch, modify app.txt by adding the line Feature branch addition, add and commit the change with the message Update on feature branch.
Git
Need a hint?

Use git checkout feature to switch branches. Use >> to append text to a file.

4
Use git diff to compare feature branch with main
Run the command git diff main..feature to see the changes made in the feature branch compared to main.
Git
Need a hint?

Use git diff main..feature to compare the two branches.