Git is a version control tool that keeps a complete history of changes to a folder of files, called a repository (repo).
GitHub is an online service that hosts these repositories, making it easy for people to collaborate, share, and work on the same code together.
Learning Objectives
You'll understand how developers manage code changes, collaborate with teams, and maintain project history using git.
Think of it like:
Git = A detailed logbook that records every change made to a document GitHub = A shared library where teams can access and contribute to the same logbooks
1Local vs Remote Repositories
Git often works with two copies of your project: one on your computer and one in the cloud (for instance, on Github). This simple concept enables powerful collaboration.
π» Your Computer
Local Repository
Work offline
Full project history
Experiment freely
β·
βοΈ GitHub
Remote Repository
Backup in cloud
Share with team
Access anywhere
Think of it like:
Working on a document on your laptop (local) while keeping a backup in Google Drive (remote) that your team can access. You can work offline on your laptop, then sync when you're ready to share.
Key Commands (we'll practice these later):
git push - Send your changes to GitHub
git pull - Get latest changes from GitHub
git clone - Copy a project from GitHub
git fetch - Check for updates
2Understanding Staging: The Photography Studio
Before learning Git commands, let's understand why Git uses a "staging area". Think of it like a photography studio where you arrange items before taking a snapshot.
π Your Working Directory (Messy Desk)
Drag files to the stage β
π index.html (modified)
π styles.css (modified)
π script.js (modified)
π test.js (work in progress)
π¬ Staging Area (Photography Stage)
Drop files here to stage them
Drop files here to prepare them for the snapshot
πΈ
Stage some files first!
π Your Photo Album (Commit History)
Your snapshots will appear here...
Why this two-step process?
Just like a photographer carefully arranges items on a stage before taking a photo, Git lets you carefully select which changes to include in each commit. This creates a clean, understandable project history where each "snapshot" has a clear purpose.
3Git Workflow
Now let's see the staging concept in action. Watch how files move from your working directory, to the stage, then into permanent snapshots (commits), and finally to the remote repository for team collaboration.
π Local Machine
Working Directory
Edit files here
homepage.html
Staging Area
Prepare to commit
Local Repository
Committed history
βοΈ GitHub (Remote)
Remote Repository
Shared team codebase - push your commits here, pull others' changes from here
Command History
$ git status
On branch main
Changes not staged for commit:
modified: homepage.html
Workflow Status
Current State: 1 modified file in working directory
Workflow Steps:
1. git add - Stage changes
2. git commit - Save locally
3. git push - Upload to remote
4. git pull - Download from remote
Note: "Reset Demo" resets this interactive demo, not the same as git reset command
Complete workflow:
Working β Staging β Local Repo β Remote Repo = Full development cycle with team synchronization
4Branch Management
Branches are separate versions of your repository that let you work on changes independently from the main version. Using branches, you can try out changes without affecting the main version until youβre ready to merge them. Try it out! Create feature branches, make commits, switch between branches, and merge.
Current Branch:main
main
A
B
C
Branch Status: On branch main with 3 commits
Think of it like:
Branches are parallel universes where you can experiment without affecting the main timeline. Successful experiments get merged back.
5Team Collaboration with Pull Requests
Here, we simulate team collaboration using git: developers work on feature branches, create pull requests for code review, and merge approved changes.
S
Sarah (Frontend)
Branch:feature-ui
Working on: Homepage redesign
M
Mike (Backend)
Branch:feature-auth
Working on: User authentication
A
Alex (DevOps)
Branch:feature-deploy
Working on: CI/CD pipeline
Pull Requests
Team Activity Log
Pull Request workflow:
Developers work independently on feature branches β Create pull requests β Team reviews code β Approved changes merge to main branch
Summary
You've now experienced the Git and GitHub workflow through interactive demonstrations:
Complete workflow: Working directory β Staging β Local repo β Remote repo
Branch management: Creating, switching, and merging branches interactively
Pull request workflow: How teams collaborate through code review
Essential commands: add, commit, push, pull, branch, merge in action