free course · YouTube + GitHub

Git & GitHub

From your first commit to a reviewed pull request that deploys itself.

modules
4
modules
lessons
12
lessons
real pull request
1
real pull request
to start
$0
to start
scroll — the course starts below

why version control

Code without Git is a folder full of final_v2.

  • Nothing is ever lostEvery version of every file, kept forever.
  • Many people, one codebaseEveryone works at once, Git puts it back together.
  • Every DevOps job needs itCI/CD, GitOps and Terraform all start in a repo.
without Git
  • app_final.py
  • app_final_v2.py
  • app_FINAL_real.py
  • app_v2_ali.py

Which one is live? Nobody knows.

with Git
  1. feat: checkout pagee4f1c2a · muh
  2. fix: total rounding9b3d07e · sara
  3. test: cover coupons1c8a4f6 · muh

One file. Every version, named and traceable.

the question everybody asks

Git is the tool. GitHub is the website.

They are two different things with confusingly similar names. Here is the whole difference.

Gitruns on your laptop
  • Saves every version of your files
  • Works with no internet at all
  • You install it once, like any tool
GitHubruns on the internet
  • Stores a copy your team can reach
  • Adds pull requests and reviews
  • Runs your pipelines on every push

You can use Git with no GitHub account at all. Teams just find that lonely.

step one

Install Git — one command.

Pick your operating system. That is the whole install.

Windows

$ winget install Git.Git

macOS

$ brew install git

Ubuntu / WSL

$ sudo apt install git

Then check it worked: git --version

step two

Tell Git who you are.

Four commands, once per machine. Then you never touch this again.

skip this and every commit says “unknown”
one-time setup~
  1. $ git config --global user.name "Your Name"

    # your name, stamped on every commit

  2. $ git config --global user.email "you@mail.com"

    # use the same email as your GitHub account

  3. $ git config --global init.defaultBranch main

    # call the first branch main, not master

  4. $ ssh-keygen -t ed25519

    # make a key, so GitHub stops asking for passwords

the one idea to get right

Your code lives in four places.

Almost every Git command just moves your work from one box to the next.

  1. Working directorythe files you are editing
    git add
  2. Staging areawhat goes in the next commit
    git commit
  3. Local repositoryevery commit, on your laptop
    git push
  4. GitHubthe copy your team shares

git clone brings it all down · git pull brings the team’s work back to you

Stuck on a Git command? Ask which two boxes it moves your code between.

module 1 of 4

Git Basics

Track your own work — save snapshots, read the history, undo anything.

  1. 01Your First Repository
  2. 02Commits — Save Points for Code
  3. 03Undo Anything

After this module: You can version any project and walk back any mistake.

git log --onelineHEAD → main
  1. a1e93f7docs: write README+1
  2. 45d1e8cfix: validate email+1 1
  3. c07a9b4feat: add login form+4
  4. 8f2b1dechore: init repo+1

Four snapshots — you can go back to any of them.

commita full snapshot of your project, not a diff

lesson 01 of 12

Your First Repository

Turn any folder into a Git repository, and meet the command you will run a thousand times.

A repository is just a folder with a .git directory inside it.

# what you will actually type

  • git --versioncheck Git is installed
  • git initturn this folder into a repository
  • git statuswhat has changed since the last save?
  • ls -asee the hidden .git folder that appeared
  • .gitignorethe list of files Git must never track

lesson 02 of 12

Commits — Save Points for Code

The everyday loop: change files, stage what you meant to change, save a snapshot.

Stage first, commit second. Staging is you choosing what goes in.

# what you will actually type

  • git add app.pystage one file for the next commit
  • git add .stage everything you changed
  • git commit -m "add login"save the snapshot, with a message
  • git log --onelinethe history, one line per commit
  • git diffshow exactly what changed, line by line

lesson 03 of 12

Undo Anything

The lesson that removes the fear — almost every mistake in Git is reversible.

Nothing is really lost until you run reset --hard. Learn revert first.

# what you will actually type

  • git restore app.pythrow away unstaged changes
  • git restore --staged app.pyunstage, but keep the changes
  • git commit --amendfix the last commit or its message
  • git revert <sha>undo a commit by adding the opposite one
  • git stashpark unfinished work, come back later

module 2 of 4

Branching & Merging

Work on two things at once — branch off, merge back, handle conflicts calmly.

  1. 04Branches Explained
  2. 05Merge Conflicts, Calmly
  3. 06Rebase & a Clean History

After this module: You can run feature branches and merge them without breaking main.

git log --graphmainfeature

Your branch leaves main, grows, and comes back as one merge.

HEADthe commit you are standing on right now

lesson 04 of 12

Branches Explained

A branch is just a movable label pointing at a commit. Once that clicks, branching stops being scary.

Branching is free. Make one for every task, delete it after merging.

# what you will actually type

  • git branchlist branches — the star is where you are
  • git switch -c feature/logincreate a branch and jump onto it
  • git switch maingo back to the main branch
  • git merge feature/loginbring that branch’s work into this one
  • git branch -d feature/logindelete it once it is merged

lesson 05 of 12

Merge Conflicts, Calmly

Two people changed the same line, so Git stops and asks you to decide.

A conflict is not an error. Git is asking a question — answer it and commit.

# what you will actually type

  • <<<<<<< HEADabove this line is your version
  • >>>>>>> featurebelow is theirs — keep one, or combine
  • git statusevery file still waiting on your decision
  • git add resolved.jstell Git this file is sorted
  • git merge --abortback out completely, nothing lost

lesson 06 of 12

Rebase & a Clean History

Replay your commits on top of the latest main, so the history reads like a story.

Rebase your own branch. Never rebase something you already shared.

# what you will actually type

  • git pull --rebaseget the latest main, no extra merge commit
  • git rebase mainmove your branch on top of main
  • git rebase -i HEAD~3squash or reword your last 3 commits
  • git cherry-pick <sha>take one commit from another branch
  • git reflogyour safety net — every move Git ever made

module 3 of 4

GitHub Workflow

Put the work online and collaborate the way real teams do.

  1. 07Remotes, Push & Pull
  2. 08Pull Requests & Code Review
  3. 09Protect main, Tag Releases

After this module: You can contribute to any repository on GitHub, including other people’s.

Add login form

#482 · feature/login main

● Open
+128−166 files changed
  • CI / testrunning…
  • CI / buildrunning…
  • reviewrunning…

checks running — merge is blocked

originjust a nickname for your GitHub URL

lesson 07 of 12

Remotes, Push & Pull

Connect your local repository to GitHub over SSH, then move commits both ways.

origin is a nickname. push sends, pull brings back, clone copies it all.

# what you will actually type

  • ssh-keygen -t ed25519create the key GitHub will trust
  • git remote add origin <url>point your repo at GitHub
  • git push -u origin mainupload your commits, first time
  • git pullfetch the team’s commits and merge them in
  • git clone <url>copy an existing repo to your machine

lesson 08 of 12

Pull Requests & Code Review

The pull request is where work gets discussed, reviewed and approved.

Small pull requests get reviewed fast. Huge ones sit for days.

# what you will actually type

  • forkyour own copy of someone else’s repository
  • open a pull requestask to merge your branch into theirs
  • request changesthe reviewer saying “not yet”
  • squash and mergeyour branch lands as one clean commit
  • gh pr create --fillopen the pull request from the terminal

lesson 09 of 12

Protect main, Tag Releases

The settings that stop broken code reaching production, and the tags that record what you shipped.

If anyone can push straight to main, main will break. Protect it on day one.

# what you will actually type

  • branch protectionno direct pushes to main
  • required checkstests must pass before merge is allowed
  • CODEOWNERSauto-assign the right reviewer per folder
  • git tag -a v1.2.0mark this exact commit as a release
  • git push --tagspublish your tags to GitHub

module 4 of 4

Git for DevOps

Use Git the way it is used at work — team branching, CI on every push.

  1. 10The Team Branching Model
  2. 11Git Triggers Everything
  3. 12Capstone: A Repo a Team Could Use

After this module: You can set up a repository a real team could start working in on day one.

GitHub Actionsgit push → a1e93f7
  1. checkout
  2. test
  3. build
  4. deploy

image: app:a1e93f7 — tagged with the exact commit

CIcontinuous integration — merge small, merge often

lesson 10 of 12

The Team Branching Model

The conventions that keep ten engineers out of each other’s way.

main is always deployable. Branches live for days, never for months.

# what you will actually type

  • mainalways deployable, always green
  • feat: add checkouta conventional commit — tools read this
  • fix: · chore: · docs:the other prefixes you will use
  • short-lived branchesmerge in a day or two, not a month
  • git log --graphsee the branching model, drawn

lesson 11 of 12

Git Triggers Everything

Every push and every pull request can run tests, build an image and deploy.

In DevOps, a git push is the button that starts the whole pipeline.

# what you will actually type

  • .github/workflows/ci.ymlthe file that defines your pipeline
  • on: [push, pull_request]Git events start the pipeline
  • ${{ github.sha }}tag the image with the exact commit
  • secrets.AWS_ROLEcredentials in GitHub, never in the repo
  • GitOpsthe repo becomes the source of truth for deploys

lesson 12 of 12

Capstone: A Repo a Team Could Use

One repository, built end to end — protected main, CI, a real pull request, a tagged release.

Finish this and you have something real to show in an interview.

# what you will actually type

  • repo + README + .gitignoreset it up like a professional
  • protect mainreviews and passing checks required
  • CI on every pull requesttests run before anyone can merge
  • feature branch → PR → reviewthe loop you repeat for years
  • tag v1.0.0 → releaseship it, and record what you shipped

the loop you repeat forever

A whole day of Git is eight commands.

Git has hundreds. These are the ones you actually run, in order.

  1. 1git pull

    start from the team’s latest main

  2. 2git switch -c feat/search

    one branch per task

  3. 3git add -p

    stage exactly what you meant to

  4. 4git commit -m "feat: …"

    a snapshot with a readable message

  5. 5git push -u origin feat/search

    send the branch to GitHub

  6. 6gh pr create --fill

    open the pull request

  7. 7CI runs green

    tests pass on your branch, not on main

  8. 8squash & merge

    one clean commit lands on main

the payoff

By the end, this is just how you work.

  • Never lose work again

    Commit, branch and stash so nothing disappears.

  • Work in parallel, safely

    Feature branches and conflicts you can resolve.

  • Contribute to any repo

    Fork, branch, pull request, review.

  • Wire Git into the pipeline

    Pushes run tests, merges trigger deploys.

muh@laptop:~/apimain ↑2

$ git switch -c fix/session-timeout

$ git commit -m "fix: extend session"

1 file changed, 4 insertions(+)

$ gh pr create --fill

github.com/acme/api/pull/482

CI green · approved · squash-merged