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

  1. Push your branch to GitHub
  2. Go to the repository page
  3. Click Compare & pull request
  4. Add a title and description
  5. 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.


This site uses Just the Docs, a documentation theme for Jekyll.