0
0
Gitdevops~15 mins

Why branches are essential in Git - See It in Action

Choose your learning style9 modes available
Why Branches Are Essential in Git
📖 Scenario: You are working on a team project where multiple people add new features and fix bugs. To keep the main project safe and organized, you use branches in Git.
🎯 Goal: Learn how to create and use branches in Git to keep your work separate and safe before merging it into the main project.
📋 What You'll Learn
Create a new branch called feature
Switch to the feature branch
Make a change (create a file) on the feature branch
Switch back to the main branch
Show that the change is only on the feature branch
💡 Why This Matters
🌍 Real World
Teams use branches to work on different features or fixes at the same time without breaking the main project.
💼 Career
Understanding branches is essential for collaborating on code safely and efficiently in software development jobs.
Progress0 / 4 steps
1
Create a new branch called feature
Use the command git branch feature to create a new branch named feature.
Git
Need a hint?

Branches let you work on new ideas without changing the main project.

2
Switch to the feature branch
Use the command git checkout feature to switch to the feature branch.
Git
Need a hint?

You must switch to the branch to start working on it.

3
Create a new file called feature.txt on the feature branch
Create a file named feature.txt with the text New feature work on the feature branch using echo, git add, and git commit.
Git
Need a hint?

Use echo "text" > filename to create a file with text, git add filename, and git commit -m "msg" to save it to the branch.

4
Switch back to the main branch and check files
Use git checkout main to switch back to the main branch. Then use ls to show that feature.txt is not present on main.
Git
Need a hint?

Switching branches changes what files you see.