What is a Branch?
A branch is a separate version of your code that allows you to work on features or fixes without affecting the main project.
퇽훹 Method 1: Create Branch in GitHub Website
Step 1: Open Repository
- Go to your repository in GitHub
Step 2: Click Branch Dropdown
- Click the branch name (usually
main) at the top
Step 3: Create New Branch
- Type a new branch name (e.g.,
feature-login) - Click Create branch
퇽훹 Method 2: Create Branch Using Git (Command Line)
Step 1: Open Terminal
Navigate to your project folder
Step 2: Create Branch
git branch feature-login
Step 3: Switch to Branch
git checkout feature-login
퇽혉 OR (both steps in one command):
git checkout -b feature-login
Step 4: Push Branch to GitHub
git push origin feature-login
퇽훹 Verify Branch
git branch
퇽훹 Why Use Branches?
- Work on new features safely
- Fix bugs without affecting main code
- Support team collaboration
- Enable parallel development
퇽훹 Example
A team creates branches like:
main᭒ stable versionfeature-login᭒ new featurebug-fix᭒ fixing errors
