GitHub Fundamentals

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:

  1. Create branch
  2. Push code
  3. Open PR
  4. 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

CommandPurpose
git initStart repo
git cloneCopy repo
git addStage changes
git commitSave changes
git pushUpload
git pullDownload updates
git branchList branches
git checkoutSwitch 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:

  1. Create a folder
  2. Add a file app.js
  3. Run:
  4. 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:

  1. Fork repository on GitHub
  2. Clone it:
git clone https://github.com/your-username/repo.git
  1. Create branch:
git checkout -b fix-bug
  1. Make changes + commit
  2. Push:
git push origin fix-bug
  1. 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

  1. Developer A creates feature branch
  2. Developer B works on another branch
  3. Both create Pull Requests
  4. Code review happens
  5. 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:

  1. Create 2 branches and merge them
  2. Create a merge conflict and resolve it
  3. Use git stash while switching branches
  4. Create a Pull Request on your own repo
  5. Add a README with project details

Leave a Comment