Welcome to Hacktoberfest 2025Tutorials
Create a Branch
Learn how to create a new branch for your changes
Create a Branch
Branches allow you to work on new features or fixes without affecting the main codebase.
Why Create a Branch?
- Isolation: Keep your changes separate from the main code
- Organization: Work on multiple features simultaneously
- Safety: Easy to discard if something goes wrong
- Best Practice: Required for pull requests
Step-by-Step Guide
Step 1: Check Current Branch
git branch
# Shows current branch (usually 'main' or 'master')Step 2: Create and Switch to New Branch
# Create and switch in one command
git checkout -b feature/my-awesome-feature
# Or use the newer syntax
git switch -c feature/my-awesome-featureStep 3: Verify You're on the New Branch
git branch
# The current branch will have an asterisk (*)
# * feature/my-awesome-feature
# mainBranch Naming Conventions
Good Branch Names
feature/add-dark-mode
fix/broken-link-footer
docs/update-readme
refactor/improve-performanceBranch Name Patterns
feature/- New featuresfix/- Bug fixesdocs/- Documentation changesrefactor/- Code refactoringtest/- Adding tests
Use descriptive names that explain what you're working on. This helps maintainers understand your changes.
Common Commands
# List all branches
git branch
# List all branches (including remote)
git branch -a
# Switch to existing branch
git checkout branch-name
# or
git switch branch-name
# Delete a branch (after merging)
git branch -d branch-name
# Force delete a branch
git branch -D branch-nameNext Steps
You've created a new branch! Now you can make changes safely. 🌿