Chapter 9: Introduction to GitHub

What is GitHub?

GitHub is a web-based platform that provides Git repository hosting along with additional collaboration features. It’s built on top of Git and adds a user-friendly interface, project management tools, and social coding features.

GitHub vs Git

Git GitHub
Version control system Hosting platform for Git repositories
Command-line tool Web-based interface
Local and distributed Cloud-based with collaboration features
Open source Proprietary platform (owned by Microsoft)
Works offline Requires internet connection

Key GitHub Features

  • Repository hosting: Store Git repositories in the cloud
  • Collaboration tools: Pull requests, issues, project boards
  • Social features: Following, starring, forking
  • CI/CD: GitHub Actions for automation
  • Documentation: Wiki, GitHub Pages
  • Security: Vulnerability scanning, secret management
  • Package management: GitHub Packages

Creating Your GitHub Account

Account Setup

  1. Visit GitHub: Go to github.com
  2. Sign up: Click “Sign up” and provide:
    • Username (choose carefully - hard to change)
    • Email address
    • Password
  3. Verify email: Check your email and verify account
  4. Choose plan: Free plan includes unlimited public/private repos

Profile Setup

# Complete your profile
- Profile picture
- Bio description
- Location
- Website/blog URL
- Company/organization
- Social media links

Account Security

# Enable two-factor authentication (2FA)
# 1. Go to Settings > Security
# 2. Enable 2FA with authenticator app or SMS
# 3. Download recovery codes

# Add SSH keys for secure authentication
ssh-keygen -t ed25519 -C "your.email@example.com"
# Add public key to GitHub Settings > SSH and GPG keys

Creating Repositories

Repository Creation Options

Option 1: Create on GitHub First

# 1. Create repository on GitHub web interface
# 2. Clone to local machine
git clone https://github.com/username/repository-name.git
cd repository-name

# 3. Start working
echo "# My Project" > README.md
git add README.md
git commit -m "Initial commit"
git push origin main

Option 2: Create Locally First

# 1. Create local repository
mkdir my-project
cd my-project
git init
echo "# My Project" > README.md
git add README.md
git commit -m "Initial commit"

# 2. Create repository on GitHub (web interface)
# 3. Add remote and push
git remote add origin https://github.com/username/my-project.git
git branch -M main
git push -u origin main

Repository Settings

Basic Settings

  • Repository name: Descriptive and clear
  • Description: Brief explanation of the project
  • Visibility: Public (anyone can see) or Private (restricted access)
  • Initialize with: README, .gitignore, license

Advanced Settings

  • Features: Issues, Wiki, Projects, Discussions
  • Pull Requests: Allow merge commits, squash merging, rebase merging
  • Branches: Default branch, branch protection rules
  • Webhooks: Integration with external services

GitHub Interface Overview

Repository Structure

Repository Page
├── Code tab (default)
│   ├── File browser
│   ├── README display
│   ├── Clone/download options
│   └── Branch selector
├── Issues tab
├── Pull requests tab
├── Actions tab (CI/CD)
├── Projects tab
├── Wiki tab
├── Security tab
├── Insights tab
└── Settings tab (if you have access)

Working with Files on GitHub

Web Editor

# Edit files directly on GitHub
1. Navigate to file
2. Click pencil icon (Edit)
3. Make changes in web editor
4. Add commit message
5. Choose commit directly or create pull request

Creating Files

# Create new file
1. Click "Create new file" button
2. Enter filename (use / for directories)
3. Add content
4. Commit with message

Uploading Files

# Upload files via web interface
1. Click "Upload files" button
2. Drag and drop or choose files
3. Add commit message
4. Commit changes

File History

# View file history
1. Navigate to file
2. Click "History" button
3. View all commits that modified the file
4. Click commit to see changes

README Files

README Importance

README files are crucial for: - First impressions: What visitors see first - Project explanation: What the project does - Usage instructions: How to use the project - Contribution guidelines: How to contribute - Documentation: Basic project documentation

README Best Practices

# Project Title

Brief description of what the project does.

## Features

- Feature 1
- Feature 2
- Feature 3

## Installation

```bash
git clone https://github.com/username/project.git
cd project
npm install

Usage

npm start

Contributing

  1. Fork the repository
  2. Create feature branch
  3. Make changes
  4. Submit pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.


### Markdown Formatting

```markdown
# Headers
## Subheaders
### Sub-subheaders

**Bold text**
*Italic text*
`Code snippets`

```code blocks```

[Links](https://example.com)
![Images](image.png)

- Bullet points
1. Numbered lists

> Blockquotes

| Tables | Are | Supported |
|--------|-----|-----------|
| Cell 1 | Cell 2 | Cell 3 |

Licenses

Why Licenses Matter

  • Legal protection: Define how others can use your code
  • Clarity: Clear terms for contributors and users
  • Open source compliance: Required for open source projects
  • Professional appearance: Shows project maturity

Common Licenses

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction...
  • Permissive: Allows almost anything
  • Popular: Widely used and understood
  • Simple: Easy to understand terms

Apache License 2.0

  • Patent protection: Includes patent grant
  • Attribution required: Must include license notice
  • Popular: Used by many large projects

GNU GPL v3

  • Copyleft: Derivative works must be open source
  • Strong protection: Ensures code remains free
  • Viral: Affects entire project if used

Adding License

# Add license file
# 1. Create LICENSE file in repository root
# 2. Copy license text
# 3. Update copyright year and name
# 4. Commit to repository

# GitHub license picker
# 1. Create repository with license option
# 2. Or add LICENSE file via web interface
# 3. GitHub provides license templates

.gitignore Files

Purpose of .gitignore

Prevent tracking of: - Build artifacts: Compiled files, build directories - Dependencies: node_modules, vendor directories - Secrets: API keys, passwords, certificates - IDE files: Editor-specific configuration - OS files: .DS_Store, Thumbs.db - Logs: Application and system logs

GitHub .gitignore Templates

# GitHub provides templates for different languages/frameworks
# Available when creating repository or adding .gitignore file

# Popular templates:
- Node.js
- Python
- Java
- C++
- Swift
- Go
- Ruby
- PHP

Custom .gitignore Example

# Dependencies
node_modules/
npm-debug.log*

# Build outputs
build/
dist/
*.min.js

# Environment files
.env
.env.local
.env.production

# IDE files
.vscode/
.idea/
*.swp

# OS files
.DS_Store
Thumbs.db

# Logs
logs/
*.log

# Runtime data
pids/
*.pid
*.seed

Repository Management

Repository Settings

General Settings

# Repository name and description
- Clear, descriptive names
- Helpful descriptions
- Appropriate topics/tags

# Features
- Enable/disable Issues
- Enable/disable Wiki
- Enable/disable Projects
- Enable/disable Discussions

Collaboration Settings

# Manage access
- Add collaborators
- Set permissions (read, write, admin)
- Create teams (for organizations)

# Branch protection
- Protect main branch
- Require pull request reviews
- Require status checks
- Restrict pushes

Repository Visibility

Public Repositories

  • Visible to everyone: Anyone can view and clone
  • Search indexing: Appears in GitHub search
  • Free: No cost for public repositories
  • Open source: Suitable for open source projects

Private Repositories

  • Restricted access: Only you and collaborators can see
  • Not searchable: Doesn’t appear in public search
  • Paid feature: Free tier includes limited private repos
  • Proprietary: Suitable for private/commercial projects

Repository Templates

# Create template repository
# 1. Go to repository settings
# 2. Check "Template repository"
# 3. Others can use "Use this template" button

# Benefits of templates:
- Standardized project structure
- Pre-configured settings
- Boilerplate code
- Consistent setup across projects

GitHub Desktop

Installation and Setup

# Download GitHub Desktop
# 1. Visit desktop.github.com
# 2. Download for your OS
# 3. Install and sign in with GitHub account

# Features:
- Visual Git interface
- Repository management
- Commit history visualization
- Branch management
- Conflict resolution tools

Basic Operations

# Clone repository
1. File > Clone repository
2. Choose from GitHub.com or URL
3. Select local path

# Make commits
1. View changes in left panel
2. Add commit message
3. Click "Commit to main"

# Push/pull changes
1. Click "Push origin" to upload
2. Click "Fetch origin" to download
3. Automatic sync notifications

Exercises

Exercise 1: Account Setup

  1. Create GitHub account if you don’t have one
  2. Complete your profile information
  3. Set up two-factor authentication
  4. Add SSH key for secure access

Exercise 2: Repository Creation

  1. Create a new public repository on GitHub
  2. Initialize with README, .gitignore, and license
  3. Clone repository locally
  4. Make changes and push back to GitHub

Exercise 3: README and Documentation

  1. Create a comprehensive README for a project
  2. Use various Markdown formatting features
  3. Include code examples and images
  4. Add proper license information

Exercise 4: Repository Management

  1. Create both public and private repositories
  2. Practice uploading files via web interface
  3. Edit files directly on GitHub
  4. Explore repository settings and features

Best Practices

Repository Organization

  1. Clear naming: Use descriptive repository names
  2. Good documentation: Comprehensive README files
  3. Proper licensing: Choose appropriate license
  4. Organized structure: Logical file and directory layout
  5. Regular updates: Keep repositories current

Collaboration Preparation

  1. Enable features: Turn on Issues, Wiki, Projects as needed
  2. Set guidelines: Create CONTRIBUTING.md file
  3. Branch protection: Protect main branch from direct pushes
  4. Templates: Use issue and pull request templates

Security Considerations

  1. Never commit secrets: Use .gitignore for sensitive files
  2. Review permissions: Regularly audit collaborator access
  3. Enable security features: Vulnerability alerts, dependency scanning
  4. Use SSH keys: More secure than password authentication

Summary

GitHub provides a comprehensive platform for Git repository hosting and collaboration:

  • Repository hosting: Secure, reliable Git repository storage
  • Web interface: User-friendly way to interact with repositories
  • Collaboration tools: Issues, pull requests, project management
  • Documentation: README files, wikis, GitHub Pages
  • Security: Access control, vulnerability scanning

Key skills developed: - Creating and managing repositories - Using GitHub’s web interface effectively - Writing good documentation - Understanding licensing - Setting up secure authentication

GitHub transforms Git from a local tool into a collaborative platform. The next chapter will explore collaboration workflows that leverage GitHub’s features for effective team development.