GitHub — Remote Repositories & Collaboration

30 minLesson 3 of 4

Learning Objectives

  • Clone repositories and configure remotes
  • Push and pull changes to/from GitHub
  • Set up SSH key authentication
  • Create and review pull requests
  • Understand forks and issues

Connecting to GitHub

Clone a Repository

# HTTPS
git clone https://github.com/username/repo.git
 
# SSH (after key setup)
git clone git@github.com:username/repo.git
# Generate key pair
ssh-keygen -t ed25519 -C "your@email.com"
 
# Copy public key
cat ~/.ssh/id_ed25519.pub

Add the public key to GitHub: Settings → SSH Keys → New SSH Key.

Push & Pull Workflow

# Make changes locally
git add .
git commit -m "Add new feature"
 
# Push to remote
git push origin main
 
# Pull latest changes from remote
git pull origin main
 
# Fetch without merging (check first)
git fetch origin

Branching Workflow with GitHub

# Create feature branch
git switch -c feature/user-auth
 
# Work, commit...
git add .
git commit -m "Implement user authentication"
 
# Push branch to GitHub
git push -u origin feature/user-auth
 
# Create Pull Request on GitHub website
# After review and merge, clean up:
git switch main
git pull origin main
git branch -d feature/user-auth

Pull Requests

Pull Requests (PRs) are how teams review and merge code:

  1. Push your branch to GitHub
  2. Click "New Pull Request" on GitHub
  3. Describe your changes
  4. Reviewers comment and approve
  5. Merge when approved
  6. Delete the branch

PR Best Practices

  • Keep PRs small and focused
  • Write clear descriptions
  • Reference related issues
  • Request specific reviewers

Forks

Fork = your own copy of someone else's repository:

  1. Click "Fork" on any public repo
  2. Clone YOUR fork locally
  3. Make changes and push to your fork
  4. Submit a PR to the original repo

This is how open-source contributions work.

Issues

Track bugs, features, and tasks:

  • Create issues for work to be done
  • Use labels (bug, enhancement, documentation)
  • Reference issues in commits: git commit -m "Fix login bug #42"
  • Close issues automatically: Fixes #42 in PR description

.gitignore

Exclude files from version control:

# .gitignore
node_modules/
.env
*.pyc
__pycache__/
.DS_Store
dist/
build/

Summary

  • git clone downloads a remote repository
  • git push sends commits to GitHub; git pull fetches and merges
  • SSH keys provide secure, passwordless authentication
  • Pull Requests enable code review before merging
  • Forks let you contribute to projects you don't own
  • .gitignore excludes files from tracking

Next Steps

Next, we'll cover Git workflows (Git Flow, GitHub Flow) and CI/CD with GitHub Actions.