Branches

🌿 Scenario

You want to develop a new feature without affecting the main codebase.

1 Create a New Branch

git checkout -b add-greeting

2 Edit the File

Modify hello.py to greet a user by name.

echo "name = input('Enter your name: ')\nprint(f'Hello, {name}!')" > hello.py

3 Add and Commit Changes

git add hello.py
git commit -m "Add user greeting feature"

4 Switch to Main and Merge

git checkout main
git merge add-greeting

5 Delete the Feature Branch

git branch -d add-greeting