Module Overview
What You'll Learn
- Set up GitHub repositories
- Push and pull changes
- Collaborate with teams
- Use Pull Requests
Time Estimate
45-60 minutes
Prerequisites
Module 3: Branching & Merging
Setting Up GitHub
Creating a GitHub Account
Get started with GitHub:
Step 1: Sign Up
- • Visit github.com
- • Click "Sign up" and create your account
- • Choose a username (this will be your GitHub handle)
- • Verify your email address
SSH Key Authentication
Set up secure authentication with SSH keys:
ssh-keygen -t ed25519 -C "your_email@example.com"
Generate a new SSH key pair
cat ~/.ssh/id_ed25519.pub
Display your public key to copy to GitHub
Adding SSH Key to GitHub
Steps:
- 1. Copy your public key from the command above
- 2. Go to GitHub Settings → SSH and GPG keys
- 3. Click "New SSH key"
- 4. Paste your public key and save
Working with Remote Repositories
Creating a Remote Repository
Create a new repository on GitHub:
On GitHub:
- 1. Click the "+" icon in the top right
- 2. Select "New repository"
- 3. Choose repository name
- 4. Select public or private
- 5. Don't initialize with README (we'll push existing code)
Connecting Local to Remote
Link your local repository to GitHub:
git remote add origin git@github.com:username/repo-name.git
Add GitHub as the origin remote
git remote -v
Verify remote repositories
Push and Pull Operations
Pushing to GitHub
Upload your local changes to GitHub:
git push -u origin main
Push and set upstream for main branch
git push
Push changes to remote (after upstream is set)
Pulling from GitHub
Download changes from GitHub:
git pull
Fetch and merge changes from remote
git fetch
Download changes without merging
Pull Requests
Creating a Pull Request
Propose changes to a repository:
Workflow:
- 1. Fork the repository (if you don't have write access)
- 2. Clone your fork locally
- 3. Create a feature branch
- 4. Make your changes and commit them
- 5. Push your branch to your fork
- 6. Create a Pull Request on GitHub
Pull Request Best Practices
Guidelines:
- • Write clear, descriptive commit messages
- • Keep changes focused and small
- • Include tests if applicable
- • Update documentation
- • Respond to review comments promptly
Team Collaboration
Branching Strategy
Organize your work with branches:
git checkout -b feature/new-feature
Create and switch to a new feature branch
Code Review Process
Review Checklist:
- • Code follows project conventions
- • No obvious bugs or issues
- • Tests pass and coverage is adequate
- • Documentation is updated
- • Security considerations addressed
Resolving Conflicts
Handle merge conflicts when they occur:
git status
Check for merge conflicts
git merge --abort
Cancel a merge if conflicts are too complex
Module Quiz
Test your understanding of remote collaboration concepts.