askesis

Git and the command line: 50 essentials

The Git commands and shell skills developers use every day: branching, rebasing, undoing mistakes, pipes, redirects, permissions and processes.

ProgrammingBeginner50 cardsFree

Practice now

Study without an account

0 of 50 seen0 graduated
Start a new repository in the current folder

Scheduled with the default Askesis timings. Progress is saved in this browser.

All 50 cards

  1. 1
    Start a new repository in the current folder
    bash
    git init
  2. 2
    Stage changes hunk by hunk
    bash
    git add -p
  3. 3
    Fix the last commit’s message or contents
    bash
    git commit --amend
    This rewrites the commit; avoid it on commits you’ve already pushed and shared.
  4. 4
    Compact history graph
    bash
    git log --oneline --graph --all
  5. 5
    git diff vs git diff --staged
    git diff shows unstaged changes; --staged shows what will go into the next commit
  6. 6
    Create a branch and switch to it
    bash
    git switch -c feature/login
  7. 7
    What does git merge do?
    Combines another branch into the current one, with a merge commit unless it can fast-forward
  8. 8
    What does git rebase main do?
    Replays your branch’s commits on top of main, giving a linear history
  9. 9
    Merge vs rebase
    Merge keeps history as it happened; rebase rewrites it to be linear. Don’t rebase commits others already have
  10. 10
    Fast-forward merge
    When the target hasn’t diverged, Git just moves the branch pointer forward; no merge commit
  11. 11
    Set work aside and get it back
    bash
    git stash
    git stash pop
  12. 12
    git reset --soft HEAD~1
    Undo the last commit, keeping its changes staged
  13. 13
    git reset HEAD~1 (mixed, the default)
    Undo the last commit, keeping its changes in the working tree, unstaged
  14. 14
    git reset --hard HEAD~1
    Undo the last commit and discard its changes entirely
    Destructive. git reflog can still find the commit for a while.
  15. 15
    Undo a pushed commit safely
    bash
    git revert <commit>
    Creates a new commit that reverses it, without rewriting history.
  16. 16
    Find a commit you “lost” after a reset or rebase
    bash
    git reflog
    The reflog records every position HEAD has been at.
  17. 17
    Apply one commit from another branch
    bash
    git cherry-pick <commit>
  18. 18
    git fetch vs git pull
    fetch downloads remote changes; pull fetches and then merges (or rebases) them
  19. 19
    Push a new branch and track it
    bash
    git push -u origin feature/login
  20. 20
    Safer force push
    bash
    git push --force-with-lease
    Refuses if the remote moved since your last fetch, so you don’t overwrite others’ work.
  21. 21
    What is .gitignore for?
    Patterns of untracked files Git should ignore, like build output and secrets
  22. 22
    Discard local changes to a file
    bash
    git restore notes.md
  23. 23
    Unstage a file but keep its changes
    bash
    git restore --staged notes.md
  24. 24
    Detached HEAD
    HEAD points directly at a commit instead of a branch; new commits are easy to lose unless you create a branch
  25. 25
    Find the commit that introduced a bug
    bash
    git bisect start
    git bisect bad
    git bisect good v1.0
    Git binary-searches history while you mark commits good or bad.
  26. 26
    Create an annotated tag
    bash
    git tag -a v1.0 -m "First release"
  27. 27
    Who last changed each line of a file?
    bash
    git blame app.ts
  28. 28
    List remotes with their URLs
    bash
    git remote -v
  29. 29
    HEAD~1 vs HEAD^2
    HEAD~1 is the first parent; HEAD^2 is the second parent of a merge commit
  30. 30
    Show files changed in the last commit
    bash
    git show --stat
  31. 31
    Print the current directory
    bash
    pwd
  32. 32
    List all files, including hidden ones, with details
    bash
    ls -la
  33. 33
    Go back to the previous directory
    bash
    cd -
  34. 34
    Search files recursively, with line numbers
    bash
    grep -rn "TODO" src/
  35. 35
    Find .log files modified more than 7 days ago
    bash
    find . -name "*.log" -mtime +7
  36. 36
    What does a pipe | do?
    Sends one command’s standard output into the next command’s standard input
  37. 37
    > vs >>
    > overwrites the file; >> appends to it
  38. 38
    Send errors to the same place as output
    bash
    command > out.log 2>&1
  39. 39
    Make a script executable
    bash
    chmod +x deploy.sh
  40. 40
    What does chmod 755 mean?
    Owner can read, write and execute; group and others can read and execute
  41. 41
    What does chmod 644 mean?
    Owner can read and write; group and others can only read
  42. 42
    Find running node processes
    bash
    ps aux | grep node
  43. 43
    kill vs kill -9
    kill sends SIGTERM (asks the process to exit); kill -9 sends SIGKILL, which can’t be caught
  44. 44
    Delete files found by find
    bash
    find . -name "*.tmp" -print0 | xargs -0 rm
    -print0/-0 handle file names with spaces.
  45. 45
    Show the exit status of the last command
    bash
    echo $?
    0 means success.
  46. 46
    && vs || between commands
    a && b runs b only if a succeeded; a || b runs b only if a failed
  47. 47
    Follow a log file as it grows
    bash
    tail -f app.log
  48. 48
    Count lines in a file
    bash
    wc -l data.csv
  49. 49
    Count how often each line occurs
    bash
    sort access.log | uniq -c | sort -rn
    uniq only merges adjacent lines, so sort first.
  50. 50
    Generate an SSH key
    bash
    ssh-keygen -t ed25519 -C "[email protected]"

Frequently asked questions

Which is safer, reset or revert?

For commits that are already pushed, revert: it adds a new commit instead of rewriting shared history.

Do the shell commands work on macOS?

Yes. They work in bash and zsh on Linux and macOS, and in WSL or Git Bash on Windows.

Can I recover a commit after git reset --hard?

Usually, yes: find it with git reflog and reset or branch to it, before Git garbage-collects it.

Intermediate

JavaScript

Master the JavaScript every developer uses daily: scope, closures, equality, array methods, promises, async/await and the event loop.

50 cards
Intermediate

Advanced JS

Fifty advanced JavaScript cards: event-loop ordering puzzles, generators and async iteration, this binding, Proxy and Reflect, modules, AbortController and coercion edge cases.

50 cards
Intermediate

TypeScript

Learn the TypeScript you use every day: narrowing, generics, keyof, mapped and conditional types, utility types, satisfies and strict mode, with code on every card.

50 cards
Beginner

Python

Learn idiomatic Python fast: comprehensions, f-strings, args and kwargs, generators, decorators, context managers and the standard library.

50 cards
Beginner

Java

Core Java with short snippets: equals vs ==, records, sealed types, collections, generics, exceptions, streams, lambdas and JVM basics.

50 cards
Beginner

C#

C# and .NET fundamentals with short snippets: value vs reference types, properties, records, nullable reference types, LINQ, async/await and DI.

50 cards
Beginner

Kotlin

Kotlin fundamentals with short snippets: null safety, val vs var, data and sealed classes, extension functions, scope functions and coroutines.

50 cards
Beginner

Swift

Swift fundamentals with short snippets: optionals, structs vs classes, protocols, enums with associated values, closures, ARC, async/await and SwiftUI.

50 cards
Beginner

Flutter

Flutter and Dart basics: null safety, futures and streams, stateless vs stateful widgets, setState, hot reload, keys, layout and state management.

50 cards
Beginner

PHP

Modern PHP 8 with short snippets: strict types, arrays, match, nullsafe and named arguments, enums, readonly, Composer, PDO and password_hash.

50 cards
Beginner

Ruby

Ruby fundamentals with short snippets: blocks, procs and lambdas, symbols, Enumerable, mixins, truthiness, method_missing, gems and Bundler.

50 cards
Beginner

Go

Go (Golang) fundamentals with short, idiomatic snippets: slices vs arrays, maps, defer, error wrapping, interfaces, goroutines, channels, select and context.

50 cards
Intermediate

Rust

Learn the Rust that the compiler keeps asking about: ownership, borrowing, lifetimes, Option and Result, traits, closures, smart pointers and async.

50 cards
Intermediate

C++

Modern C++ in short snippets: references vs pointers, RAII, smart pointers, move semantics, STL containers and algorithms, const, templates and UB.

50 cards
Intermediate

Haskell

Haskell fundamentals with short code: types and type classes, pattern matching, laziness, Maybe and Either, folds, Functor, Applicative and Monad.

50 cards
Intermediate

Elixir

Elixir fundamentals with short snippets: immutability, pattern matching, the pipe operator, Enum vs Stream, processes, GenServer, supervisors and mix.

50 cards
Intermediate

x86-64 assembly

x86-64 assembly in Intel syntax: registers and sub-registers, flags, mov and lea, jumps, the stack frame, the System V calling convention and Linux syscalls.

50 cards
Beginner

Regex

Learn regular expressions for good: anchors, classes, greedy vs lazy quantifiers, groups, lookarounds, flags, replacements and the backtracking trap.

50 cards