Skip to main content
DevOpsLabTH.dev

Git

The commit hygiene, branching strategy, and conflict resolution that keep PRs fast and reviewers happy.

beginner31 labs
By the end you'll be able to
  • Write commits a reviewer can actually read
  • Resolve merge conflicts without rage-deleting branches
  • Recover work after a bad rebase
  • Keep a clean PR without forcing-push panic

Labs

  1. 01
    What is version control
    Before any command, build a mental model of version control as a tool that tracks every change, lets teams collaborate, and lets you travel back in time.
    10 min
    Start
  2. 02
    What is a Git repository
    A Git repository is just a folder with a hidden `.git/` directory inside. Once you see what is in there, the magic dissolves.
    15 min
    Start
  3. 03
    What is a commit
    A commit is a snapshot of your project plus a pointer to the commit before it. See the raw object Git wrote on disk.
    15 min
    Start
  4. 04
    What is a branch and HEAD
    A branch is a movable pointer to a commit. HEAD is a pointer to the branch you are currently on. See both as plain text files on disk.
    15 min
    Start
  5. 05
    The three areas, working, staged, committed
    Every file in a Git repo lives in one of three areas. Walk a single file through each one and watch `git status` change.
    20 min
    Start
  6. 06
    Configure Git identity
    Set your name and email so Git can stamp every commit you make.
    15 min
    Start
  7. 07
    Initialize a repo
    Turn an empty folder into a Git repository with one command and inspect what was created.
    10 min
    Start
  8. 08
    Check repo state with git status
    Read what Git knows about your working tree in three classic situations.
    15 min
    Start
  9. 09
    Stage changes with git add
    Move files into the staging area with single-file, bulk, and patch-mode forms of git add.
    20 min
    Start
  10. 10
    Save snapshots with git commit
    Record staged changes into history and read them back with git log.
    15 min
    Start
  11. 11
    View history with git log
    git log walks back through commits. Plain, oneline, and limited views answer different questions.
    15 min
    Start
  12. 12
    See what changed with git diff
    git diff shows pending changes. Plain, --staged, and commit-range forms cover the everyday questions.
    20 min
    Start
  13. 13
    Inspect a single commit with git show
    git show prints one commit's metadata and diff. Pair it with git log to audit a specific change.
    15 min
    Start
  14. 14
    Visualize history with git log --graph
    git log --graph draws an ASCII tree of commits. Combined with --all and --decorate it shows every branch in one view.
    20 min
    Start
  15. 15
    Discard working-tree changes with git restore
    Throw away unwanted edits in the working tree and unstage files with `git restore`.
    15 min
    Start
  16. 16
    Move HEAD back with git reset (soft, mixed, hard)
    Rewind history with `git reset` and feel the difference between `--soft`, `--mixed`, and `--hard`.
    25 min
    Start
  17. 17
    Undo a public commit safely with git revert
    Undo a commit on a shared branch by adding a new commit that reverses it, instead of rewriting history.
    20 min
    Start
  18. 18
    Recover lost commits with git reflog
    Use `git reflog` to find commits that became unreachable after a hard reset and bring them back.
    20 min
    Start
  19. 19
    Create and list branches
    A branch is a movable pointer to a commit. `git branch` lists them, `git branch <name>` creates one.
    15 min
    Start
  20. 20
    Move between branches with git switch
    `git switch` moves HEAD between branches. `-c` creates and switches in one step. `git checkout` is the legacy verb.
    15 min
    Start
  21. 21
    Detached HEAD, what it means and how to get out
    Recognize the detached HEAD state, commit safely while in it, and rescue the work with a new branch.
    15 min
    Start
  22. 22
    Merge branches (fast-forward and three-way)
    git merge folds one branch into another. The shape of the merge depends on whether the branches diverged.
    25 min
    Start
  23. 23
    Delete branches with -d vs -D
    `git branch -d` refuses to drop unmerged work. `git branch -D` forces the delete and discards the commits.
    20 min
    Start
  24. 24
    What origin means
    origin is just a name. It is an alias for a remote URL or path that git remembers per repo.
    15 min
    Start
  25. 25
    Clone a repo locally
    git clone copies a repo into a new folder and wires origin to its source. Practice it against a local bare repo.
    20 min
    Start
  26. 26
    git fetch vs git pull
    fetch downloads without merging. pull is fetch plus merge. Practice both against two clones of the same bare repo.
    25 min
    Start
  27. 27
    Push commits with git push (-u and --force-with-lease)
    git push sends local commits to a remote. -u records upstream tracking so later pushes need no arguments. --force-with-lease is the safer alternative to --force.
    20 min
    Start
  28. 28
    HTTPS vs SSH auth for GitHub
    Generate an ed25519 SSH key, inspect a remote URL, and switch a remote from HTTPS to the SSH form.
    15 min
    Start
  29. 29
    Resolve merge conflicts by hand
    When two branches change the same line, `git merge` stops with conflict markers. Edit the file, stage it, and commit to finish the merge.
    25 min
    Start
  30. 30
    Abort a merge and recover the pre-merge state
    Walk back a conflicted merge with `git merge --abort` and end up with a clean working tree on the original branch.
    15 min
    Start
  31. 31
    Capstone, integrate a conflicting branch
    A realistic team scenario. A feature branch and main both edited the same config line. Merge them and resolve the conflict by hand, keeping the feature's value and main's other change, then commit the merge.
    22 min
    Start