Lesson 5: Working with GitHub
What You'll Learn
In this lesson, you'll learn how to create repositories on GitHub, understand repository settings, and prepare your project for online collaboration.
What is GitHub?
GitHub is a cloud-based hosting service for Git repositories. Think of it as:
- Google Drive for code - stores your code online
- Social network for developers - follow projects, contribute to code
- Portfolio - showcase your work to employers
- Collaboration platform - work with teams on the same code
Part 1: Creating a Repository on GitHub
Step 1: Log In to GitHub
Go to github.com and sign in with your account.
Step 2: Create a New Repository
- Click the + icon in the top-right corner
- Select New repository
- Fill in the repository details:
Repository Settings Explained
| Setting | What It Means | Recommendation |
|---|---|---|
| Repository name | Name of your project | Use lowercase with hyphens: my-first-project |
| Description | Brief explanation of your project | Optional but helpful: "Learning Git basics" |
| Public/Private | Who can see your code | Public for learning, Private for sensitive projects |
| Initialize with README | Creates a README.md file automatically | Check this for new projects |
| .gitignore | Files Git should ignore | Select "Node" if using Node.js |
| License | How others can use your code | MIT is common for open source |
Step 3: Click "Create repository"
Your new repository is now created on GitHub!
Part 2: Understanding the Repository Page
After creating a repository, you'll see several tabs and sections:
| Tab | Purpose |
|---|---|
| Code | Browse your files and folders |
| Issues | Track bugs and feature requests |
| Pull requests | Review and merge code changes |
| Actions | Automated workflows (CI/CD) |
| Settings | Configure repository options |
Part 3: The README File
What is README.md?
A README is the front page of your repository. It's written in Markdown (.md) format and typically includes:
- Project title
- Description - what the project does
- Installation instructions - how to set it up
- Usage examples - how to use it
- Contributing guidelines - how others can help
- License information
Example README.md
# My First Git Project
A simple project to learn Git and GitHub basics.
## Description
This project contains examples from my Git learning journey.
## Installation
```bash
git clone https://github.com/yourusername/my-first-project.git
cd my-first-project
```
## Usage
Open index.html in your browser.
## License
MIT License
Part 4: The .gitignore File
What is .gitignore?
This file tells Git which files and folders to ignore. Common things to ignore:
- node_modules/ - installed dependencies (large and can be reinstalled)
- .env - environment variables (often contains secrets)
- .DS_Store - macOS system files
- *.log - log files
- dist/ or build/ - compiled code
Example .gitignore for Node.js
# Dependencies
node_modules/
# Environment variables
.env
.env.local
# macOS
.DS_Store
# Logs
*.log
npm-debug.log*
# Build output
dist/
build/
Why This Matters
Ignoring unnecessary files keeps your repository clean and prevents accidentally committing sensitive information like passwords or API keys.
Part 5: Connecting Local Repository to GitHub
You have two options:
Option 1: Start on GitHub, Clone Locally
- Create the repository on GitHub (as shown above)
- Copy the repository URL
- Clone it to your computer:
git clone https://github.com/yourusername/my-first-project.git
cd my-first-project
Option 2: Start Locally, Push to GitHub
- Create a local repository (if you haven't already):
git init
git add .
git commit -m "Initial commit"
- Create an empty repository on GitHub (don't initialize with README)
- Connect your local repo to GitHub:
git remote add origin git@github.com:yourusername/my-first-project.git
git branch -M main
git push -u origin main
Understanding the Commands
| Command | What It Does |
|---|---|
git remote add origin URL |
Links your local repo to GitHub (origin = nickname for GitHub) |
git branch -M main |
Renames your branch to "main" |
git push -u origin main |
Uploads your code to GitHub for the first time |
Part 6: Repository Visibility
Public vs Private Repositories
| Type | Who Can See | Best For |
|---|---|---|
| Public | Everyone on the internet | Open source projects, portfolio work, learning projects |
| Private | Only you and collaborators you invite | Work projects, sensitive code, unfinished projects |
Note: You can change visibility later in Settings.
Practice Exercise
- Create a new public repository on GitHub called "git-practice"
- Initialize it with a README
- Add a .gitignore file for Node
- Clone it to your computer
- Edit the README.md file locally
- In the next lesson, you'll learn how to push your changes back to GitHub!
Summary
What You Learned
| Concept | Description |
|---|---|
| GitHub | Cloud hosting for Git repositories |
| Repository | A project stored on GitHub |
| README.md | Project documentation file |
| .gitignore | Files Git should not track |
| Clone | Download a repository from GitHub |
| Remote | Connection between local and GitHub |
What's Next?
In the next lesson, you'll learn how to push your local changes to GitHub and pull changes from GitHub to your computer - keeping everything in sync!