1. What is GitHub?
- GitHub is a platform to store, manage, and collaborate on code.
- It uses Git (a version control system).
π Think of GitHub as:
βGoogle Drive for code + collaboration tools for developersβ
2. What is Git?
- Git tracks changes in your code.
- Helps you:
- Save versions
- Undo mistakes
- Work with teams
3. Repository (Repo)
A repository is a project folder stored on GitHub.
Example:
my-project/
βββ index.html
βββ style.css
βββ script.js
π This entire folder = 1 repository
4. Clone a Repository
Copy a GitHub repo to your local machine.
Command:
git clone https://github.com/user/project.git
Example:
git clone https://github.com/deepesh/my-app.git
5. Basic Git Workflow
The most important concept π
Working Directory β Staging Area β Repository
Steps:
git add file.js # Add file to staging
git commit -m "Added feature" # Save changes
git push # Upload to GitHub
6. Commit
A commit is a snapshot of your code.
Example:
git commit -m "Fixed login bug"
π Good commit message = clear + meaningful
7. Branch
A branch lets you work on features without affecting main code.
Example:
git branch feature-login
git checkout feature-login
Or shortcut:
git checkout -b feature-login
8. Merge
Combine changes from one branch into another.
Example:
git checkout main
git merge feature-login
9. Pull Request (PR)
- A Pull Request is used to merge code on GitHub.
- You request others to review your code.
π Workflow:
- Create branch
- Push code
- Open PR
- Review β Merge
10. Push & Pull
Push (upload changes):
git push origin main
Pull (get latest changes):
git pull origin main
11. Fork
A fork is a copy of someone else’s repository.
π Used in open-source contributions.
12. .gitignore
Tells Git which files to ignore.
Example:
node_modules/
.env
*.log
13. Real Example Workflow
Letβs say you’re building a JavaScript project:
Step 1: Initialize repo
git init
Step 2: Add files
git add .
Step 3: Commit
git commit -m "Initial project setup"
Step 4: Connect GitHub
git remote add origin https://github.com/user/project.git
Step 5: Push
git push -u origin main
14. Common Commands Cheat Sheet
| Command | Purpose |
|---|---|
git init | Start repo |
git clone | Copy repo |
git add | Stage changes |
git commit | Save changes |
git push | Upload |
git pull | Download updates |
git branch | List branches |
git checkout | Switch branch |
15. Best Practices
- β Commit often
- β Use clear commit messages
- β Use branches for features
- β Pull before push
- β Donβt push sensitive data
π― Mini Practice Exercise
Try this:
- Create a folder
- Add a file
app.js - Run:
- Push it to GitHub
git init
git add .
git commit -m "First commit"
git push
Pro Tip
Start with:
- Personal projects
- Practice branching + PRs
Thatβs how real developers learn GitHub fast.
16. GitHub Issues (Task Tracking)
- Issues are used to track bugs, tasks, or feature requests.
Example:
You create an issue:
Title: Fix login error
Description: Login fails when password is incorrect
π You can:
- Assign team members
- Add labels (bug, feature, urgent)
- Track progress
π 17. Labels (Organizing Work)
Labels help categorize issues.
Example labels:
bugπenhancementπdocumentationπ
π Helps teams quickly understand task types.
π 18. GitHub Projects (Kanban Board)
GitHub provides project boards similar to Trello.
Example workflow:
To Do β In Progress β Done
π You can drag issues between columns.
π 19. README.md File
This is the first file people see in your repo.
Example:
# My AppThis is a simple JavaScript project.## Features
- Login system
- Dashboard
π A good README increases project visibility.
βοΈ 20. GitHub Actions (Automation)
- GitHub Actions lets you automate workflows.
Example:
Run tests automatically when code is pushed.
name: Test App
on: [push]jobs:
test:
runs-on: ubuntu-latest
steps:
- run: echo "Running tests..."
π Used for:
- CI/CD (Continuous Integration / Deployment)
- Auto testing
- Deployment
π 21. Pull vs Fetch
Git Pull:
git pull origin main
π Fetch + merge
Git Fetch:
git fetch
π Only downloads changes (no merge)
π 22. Merge Conflict (Important!)
Occurs when Git can’t merge automatically.
Example conflict:
<<<<<<< HEAD
console.log("Hello");
=======
console.log("Hi");
>>>>>>> branch
π You must manually fix it:
console.log("Hello Hi");
Then:
git add .
git commit -m "Resolved conflict"
π§ͺ 23. Stash (Temporary Save)
Save changes without committing.
git stash
Restore:
git stash pop
π Useful when switching branches quickly.
π 24. Git Log (History)
View commit history:
git log
Short version:
git log --oneline
βͺ 25. Undo Changes
Undo staged file:
git reset file.js
Undo last commit:
git reset --soft HEAD~1
Discard changes:
git checkout -- file.js
π 26. Remote Repository
Link your local repo to GitHub.
git remote add origin https://github.com/user/repo.git
Check:
git remote -v
π 27. SSH vs HTTPS
Two ways to connect GitHub:
HTTPS:
https://github.com/user/repo.git
SSH:
git@github.com:user/repo.git
π SSH is more secure (no need to enter password repeatedly)
π¦ 28. Fork + Clone + PR (Real Open Source Flow)
Step-by-step:
- Fork repository on GitHub
- Clone it:
git clone https://github.com/your-username/repo.git
- Create branch:
git checkout -b fix-bug
- Make changes + commit
- Push:
git push origin fix-bug
- Create Pull Request
π This is how open-source contributions work.
π§± 29. Rebase (Advanced Concept)
Instead of merge, you can use rebase for cleaner history.
git checkout feature
git rebase main
π Keeps history linear (no extra merge commits)
π·οΈ 30. Tags (Versioning)
Used for releases.
git tag v1.0
git push origin v1.0
π Example:
- v1.0 β first release
- v2.0 β major update
Real-World Scenario (Important)
Scenario: Team Development
- Developer A creates feature branch
- Developer B works on another branch
- Both create Pull Requests
- Code review happens
- Merge into main
π This prevents breaking the main codebase.
π§ Pro Learning Tips
- Practice daily with small repos
- Break code β fix using Git
- Try merge conflicts intentionally
- Explore open-source repos
π» Practice Tasks (Next Level)
Try these:
- Create 2 branches and merge them
- Create a merge conflict and resolve it
- Use
git stashwhile switching branches - Create a Pull Request on your own repo
- Add a README with project details