Branches & Pull Requests
Branching
Branches let you work on features without affecting the main codebase.
# Create and switch to a new branch
git checkout -b feature/add-login
# List branches
git branch
# Switch to an existing branch
git checkout main
Workflow
gitGraph
commit
branch feature
checkout feature
commit
commit
checkout main
merge feature
commit
Pull Requests
A pull request is a proposal to merge changes from one branch into another.
Creating a PR
- Push your branch to GitHub
- Go to the repository page
- Click Compare & pull request
- Add a title and description
- Click Create pull request
Or use the CLI:
gh pr create --title "Add login page" --body "Implements the login form"
Code Review
| Action | Description |
|---|---|
| Comment | Leave feedback without approving |
| Approve | Mark the PR as ready to merge |
| Request changes | Block merge until issues are fixed |
Merging
Three merge strategies are available:
- Merge commit - preserves full history
- Squash and merge - combines all commits into one
- Rebase and merge - applies commits on top of the base branch
Always delete the branch after merging to keep the repository clean.