Free tutorial · 20 lessons

Git & Command Line Tutorial

Learn the command line and Git from scratch: navigating folders, working with files, searching, pipes and scripts, then Git step by step: commits, history, undoing changes, .gitignore, branches, merging and conflicts, rebasing, remotes, pull requests, stash, reflog and bisect. Every example is a real script shown with its output.

Start learning →

Command Line Basics

  1. Git & Command Line Introduction — What the command line is, why developers use it every day, and what Git does. A first look at both.
  2. Navigating the File System — Know where you are with pwd, list files with ls, move around with cd, and understand absolute vs relative paths, ~ and ..
  3. Creating, Copying, Moving and Deleting — Create files and folders, copy and move them, rename, and delete safely, including the commands that can't be undone.
  4. Viewing and Searching Files — Read files with cat, head, tail and less; count with wc; search text with grep and find files with find.
  5. Pipes and Redirection — Connect commands with | so the output of one feeds the next, and send output to files with >, >> and 2>. The real power of the command line.
  6. Variables, PATH and Your First Script — Use shell and environment variables, understand PATH and which, and write a reusable bash script with arguments and exit codes.
  7. Git History & Versions — How Linus Torvalds wrote Git in a few weeks in 2005 to manage the Linux kernel, how it beat older version control systems, the milestones from 0.99 to 2.56 on one timeline, and how hosting services made it universal.

Git Basics

  1. Setting Up Git and Creating a Repository — Configure your name and email, set the default branch to main, create a repository with git init, and understand what the .git folder is.
  2. Staging and Committing — The three areas of Git (working directory, staging area, commits), git status, git add, and writing commits with good messages.
  3. Viewing History and Differences — Explore history with git log, see exactly what changed with git diff and git show, and find who changed a line with git blame.
  4. Undoing Changes — Undo safely at every stage: discard edits with git restore, unstage, amend the last commit, revert a commit, and reset when you really mean it.
  5. Ignoring Files with .gitignore — Keep build output, dependencies, logs and secrets out of your repository with .gitignore patterns, and stop tracking files that were committed by mistake.

Branching and Collaboration

  1. Branches — Work on features in isolation with branches: create, switch, list and delete them, and understand that a branch is just a movable pointer to a commit.
  2. Merging and Resolving Conflicts — Bring branches together with git merge, understand fast-forward vs merge commits, and resolve conflicts when two branches changed the same lines.
  3. Rebasing — Replay your commits on top of the latest main with git rebase for a straight history, squash messy commits with interactive rebase, and know when not to rebase.
  4. Remotes: clone, fetch, pull and push — Work with a shared repository: clone it, push your branch, fetch and pull others' work, track upstream branches, and handle a rejected push.
  5. Pull Requests and Team Workflow — How teams use branches, pull requests and code review: GitHub Flow, keeping branches short-lived, conventional commit messages, and tags for releases.
  6. Stashing Work in Progress — Put unfinished changes aside with git stash to switch branches or pull, then bring them back with stash pop.

Git Superpowers

  1. Recovering Lost Work with reflog — Git rarely loses anything: use the reflog to find commits after a bad reset, a deleted branch or a messed-up rebase, and bring them back.
  2. Finding Bugs with git bisect — When something broke but you don't know which commit did it, git bisect binary-searches history, and git bisect run can do it automatically with a test script.

Was this page helpful?