BeginnerLesson 2 of 9

Introduction to Git & GitHub

Understand the difference between Git and GitHub, how local and remote repositories work together, and the basic command flow teams use every day.

Simple Explanation (ELI5)

Git is the engine on your laptop that tracks your code history. GitHub is the online platform where teams share that history, review changes, and collaborate. Think of Git as your local notebook and GitHub as the shared team workspace.

Technical Explanation

Git is a distributed version control system. GitHub is a remote hosting and collaboration platform built around Git repositories. Typical workflow: clone remote repo, create local commits, push branch to GitHub, open pull request, run checks, merge to main branch.

Git vs GitHub

AspectGitGitHub
TypeVCS toolHosting + collaboration platform
Runs whereLocal machineCloud web service
Primary functionTrack file historyPRs, code review, issues, actions
Offline usageYesNo (needs network)
Core commandscommit, branch, mergepull request, review, checks

Visual: Local to Remote Flow

Local Repo
(Git)
push →
GitHub Repo
(remote)
PR →
Code Review
merge →
main

Basic Git Commands

bash
# Clone repository from GitHub
git clone https://github.com/org/project.git
cd project

# Create branch
git checkout -b feature/login-page

# Commit work
git add .
git commit -m "Add login page layout"

# Push branch to GitHub
git push -u origin feature/login-page

# Update local branch with latest main
git checkout main
git pull origin main

# Switch back to feature and rebase
git checkout feature/login-page
git rebase main

Real Team Workflow

  1. Developer creates feature branch from main.
  2. Local commits with small logical changes.
  3. Push branch to GitHub and open pull request.
  4. CI checks run (tests/lint/security).
  5. Teammates review and request changes.
  6. After approval, PR is merged to main.
  7. Release pipeline deploys from main.
Tip: Keep main always deployable. Treat feature branches as temporary and short-lived.

Debugging Scenarios

Real-world Use Case

A distributed team across three time zones uses GitHub pull requests as async communication. Every feature includes description, screenshots, and linked issue. Even with no overlap in working hours, code quality remains high due to predictable review workflow and CI gates.

Interview Questions

Beginner

What is the difference between Git and GitHub?

Git is a version control tool; GitHub is a platform for hosting and collaborating on Git repositories.

What does git clone do?

Downloads a full copy of a remote repository and its history to your local machine.

What is origin in Git?

The default alias name for your primary remote repository.

Why create branches?

To isolate work safely and avoid directly destabilizing main.

What is a pull request?

A proposal to merge branch changes into another branch, with review and checks.

Intermediate

Why use rebase before opening PR?

It keeps commit history linear and reduces merge conflict complexity.

How does tracking branch work?

git push -u origin branch links local branch to remote branch for shorter future commands.

HTTPS vs SSH for GitHub auth?

HTTPS usually uses PAT tokens; SSH uses keypairs and avoids repeated token prompts.

What is fork workflow?

Contributors fork repo to personal namespace, push changes there, then open PR to upstream repo.

How do protected branches help?

They enforce checks/reviews and prevent direct unsafe pushes to critical branches.

Scenario-based

PR is blocked by failing checks. What do you do?

Inspect CI logs, reproduce locally, fix issue, push update, and re-run checks.

Teammate force-pushed over shared branch.

Recover lost commits from reflog, restore branch state, and enforce protected branch policy.

Need urgent hotfix during feature freeze.

Create hotfix branch from main, implement minimal fix, fast-track PR review, merge and tag release.

Two remotes (origin/upstream) confusion.

Use git remote -v, fetch upstream, rebase feature from upstream/main, push to origin.

New joiner asks where to start in GitHub repo.

Point to README, contributing guide, issue labels, and a “good first issue” branch workflow.

Summary

Git and GitHub are complementary: Git manages code history, GitHub enables team workflows around that history. Mastering both is essential for professional software collaboration.