🏠 Homepage 🏠 Syllabus of Day 2 ⬅️ Previous: 📂 Introduction of Day 2
A branch in Git is a lightweight movable pointer to a commit. It allows you to work on new features, bug fixes, or experiments in isolation from the main codebase.
You can create a new branch using:
git branch my-feature-branch
Or create and switch to a new branch in one step:
git checkout -b my-feature-branch
With newer versions of Git, you can also use:
git switch -c my-feature-branch
To switch to an existing branch:
git checkout my-feature-branch
Or with the new command:
git switch my-feature-branch
feature/login-page
, bugfix/fix-header
, docs/update-readme
.git checkout -b feature/add-login
git add .
git commit -m "Add login feature"
git push origin feature/add-login
Action | Command Example |
---|---|
Create branch | git branch my-feature-branch |
Create & switch branch | git checkout -b my-feature-branch |
Switch branch | git checkout my-feature-branch |
Push branch | git push origin my-feature-branch |
Tip:
Always create a new branch for each feature or fix to keep your work organized and make collaboration
➡️Up Next: Making Changes & Committing