GitHub: Repositories, Forks & Pull Requests
GitHub is the dominant platform for hosting Git repositories, collaborating on code, and managing software projects. Pull Requests are the primary collaboration mechanism.
Repository Setup
# Create repo via GitHub CLI
gh repo create my-project --public --clone
gh repo create my-org/my-project --private --clone
# Clone a repo
git clone https://github.com/owner/repo.git
gh repo clone owner/repo # same but uses gh auth
# View repo info
gh repo view owner/repo
gh repo view owner/repo --web # open in browser
# Set remote for existing local repo
git remote add origin https://github.com/owner/repo.git
git push -u origin mainForking Workflow
# Fork and clone
gh repo fork owner/repo --clone
cd repo
git remote -v
# origin https://github.com/YOU/repo.git
# upstream https://github.com/owner/repo.git
# Sync fork with upstream
git fetch upstream
git checkout main
git merge upstream/main # or: git rebase upstream/main
git push origin main
# Keep fork branch up to date
git checkout feature/my-work
git rebase upstream/mainPull Requests
# Create PR
git checkout -b feature/user-auth
# ... make changes ...
git add -p # stage interactively
git commit -m "feat: add JWT authentication"
git push -u origin feature/user-auth
gh pr create \
--title "Add JWT authentication" \
--body "Implements RS256 JWT auth with refresh tokens. Closes #42" \
--base main \
--reviewer alice,bob \
--label "feature,auth" \
--assignee "@me"
# List and view PRs
gh pr list
gh pr list --state all --author "@me"
gh pr list --label "needs-review"
gh pr view 42
gh pr view 42 --web
# Check out someone else's PR locally
gh pr checkout 42
# Update PR
gh pr edit 42 --title "New title" --add-label "ready"
# Merge
gh pr merge 42 --squash --delete-branch
gh pr merge 42 --rebase
gh pr merge 42 --merge
# Review
gh pr review 42 --approve
gh pr review 42 --request-changes --body "Please add tests for edge cases"Branch Protection Rules
Require pull request before merging: nobody can push directly to main
Require status checks: CI must pass before merge
Require branches to be up to date before merging: no stale PRs
Require conversation resolution: all review comments must be resolved
Restrict who can push: limit direct pushes to specific people/teams
Require signed commits: all commits must be GPG-signed
Do not allow force pushes: prevents --force on protected branch
PR Templates
<!-- .github/pull_request_template.md -->
## Summary
<!-- What does this PR do? -->
## Changes
-
-
## Testing
- [ ] Unit tests added/updated
- [ ] Integration tests pass
- [ ] Tested locally
## Screenshots (if UI changes)
## Related Issues
Closes #
## Checklist
- [ ] Code reviewed by self
- [ ] No sensitive data exposed
- [ ] Documentation updated if neededKeep your own version of these notes — editable, searchable, and organised by your stack.
Start free