Back
Unit 1
Unit 2
Unit 3
Unit 4
Unit 5
Unit 6
Unit 7
Computing and the Command Line · Course 2 of 4
Git and Version Control
Git from the first commit to confident everyday use, on the command line. The three areas, staging and committing well, reading history and undoing changes, branches, merging and rebasing, remotes and GitHub over SSH, pull requests, fixing mistakes with reset, the reflog, stash, cherry-pick, and bisect, and how git stores everything as objects, ending with your dotfiles under version control, ready for a new Linux machine.
0 of 19 done
Start learning
Getting Started
- 1 Why Version Control, and How Git Thinks You stage a file for git, edit it again, then commit without staging again. Which version goes into the commit? Version control records every saved state of a project so you can see what changed, go back, and work on several things at once. Git, written in 2005 for the Linux kernel, stores history as… Next up
- 2 Installing and Configuring Git A file edited on both Windows and Linux suddenly shows every line as changed in git. The likely cause? Install git under WSL or on Linux with apt and check the version. Set your name and email, which go into every commit; make new repositories start on a branch called main; choose your editor; and… Next up
-
3
Your First Repository
You delete the hidden
.gitfolder inside a project. What’s left? Turn a folder into a repository with git init, then go around the basic loop: git status to see where things stand, git add to stage, git commit to save a snapshot, git log to see history, and git… Next up
The Everyday Workflow
- 4 Staging and Committing Well You rename a file by hand, deleting the old name and adding the new, instead of telling git it’s a rename. How does git know? Good history is made of small commits, each one logical change, with messages that say what it does. Stage part of a file with git add -p, check for whitespace mistakes with git diff --check, write… Next up
- 5 Ignoring Files and Reading History You commit a password by accident and push it, then delete the file in a new commit. Is the password safe now? Keep logs, build output, and secrets out of a repository with .gitignore: wildcards, folder patterns, anchored paths, and exceptions, plus a personal ignore file for every repository and git… Next up
-
6
Undoing Changes
You use
git commit --amendto fix a typo in your last commit’s message. What happens to that commit? The everyday undos, matched to the situation: git restore to throw away an edit, git restore --staged to unstage, git restore --source to bring back an old version of a file, git commit --amend to… Next up
Branches
- 7 What a Branch Is On a new branch you commit a new file, then switch back to main. What happens to the file in your folder? A branch is a lightweight, movable pointer to a commit, and HEAD points to the branch you're on; committing moves the current branch forward. Create and switch with git switch -c, move between… Next up
- 8 Merging and Conflicts On two branches, you and a friend each edit the same file, but different paragraphs of it. What happens when you merge? git merge brings another branch's work into the one you're on. If your branch hasn't moved, it's a fast-forward: the pointer just slides ahead. If both have moved, git makes a three-way merge commit… Next up
- 9 Rebasing You bring your branch up to date with main by rebasing instead of merging. How do the resulting files differ? Rebasing takes your branch's commits and replays them on top of another branch, giving a straight history instead of a merge commit. The new commits get new IDs, which is why the golden rule says… Next up
Remotes and GitHub
-
10
Clone, Fetch, Pull, Push
A friend pushed to GitHub an hour ago. Without fetching, you run
git status, which says you’re up to date. Why? A remote is another copy of the repository, usually named origin. Clone copies one; fetch downloads new commits and moves your remote-tracking branches like origin/main without touching your work… Next up - 11 GitHub over SSH Your SSH key lets you push to GitHub with no password. What does giving the key a passphrase protect against? GitHub hosts remotes and adds pull requests, issues, and a web view. Connect with an SSH key: generate an Ed25519 key pair with a passphrase, let ssh-agent remember it, add the public key to your… Next up
- 12 Pull Requests You want to propose a fix to a stranger’s public project on GitHub, but you can’t push to it. Where do you push your branch? A pull request proposes merging one branch into another and gathers the discussion, review, and automatic checks around it. The feature-branch workflow step by step: branch, commit, push the branch… Next up
Fixing Mistakes
- 13 Reset, Revert, and the Reflog A commit you dropped with a reset is no longer on any branch. Left alone, how long does git keep it recoverable by default? git reset moves your branch back to an earlier commit, and its three modes decide what happens to the work you undid: --soft leaves it staged, --mixed (the default) leaves it in your files, and… Next up
-
14
Stash and Cherry-pick
You’ve edited a tracked file and created one brand-new file git has never seen. You run
git stash. What’s left in your folder? git stash shelves unfinished edits without a commit, leaving a clean working directory so you can switch branches or pull; pop or apply brings them back, list and show see what's there, and -u… Next up -
15
Finding a Bug with Bisect
git bisectnames the commit that broke something. When is its answer least useful? When something worked once and doesn't now, git bisect finds the commit that broke it by binary search: mark a bad commit and a good one, test the commit git checks out halfway between, answer good… Next up
How Git Works Inside
- 16 Objects: Blobs, Trees, and Commits In a git repository you make a script executable, and loosen another file’s group permissions. Which change does git see? Underneath, git is a key-value store: each object is saved under a hash of its contents. Three kinds of object hold a whole project's history: blobs for file contents, trees for folders (names… Next up
-
17
References and the Commit Graph
You tag a release
v1.0and run a plaingit push. Does the tag reach GitHub? A reference is a name that holds a commit ID: branches in refs/heads, tags in refs/tags, remote-tracking branches in refs/remotes, and HEAD, which usually names a branch. Lightweight and annotated… Next up
Project: Your Dotfiles
- 18 Your Dotfiles in Git You want to test a script that installs files into your home folder, without touching your real one. What’s a simple trick? Dotfiles are the hidden settings files in your home folder. This project puts yours in a git repository: ~/.bash_aliases, ~/.inputrc, ~/.nanorc, a global gitignore, and shared git settings, plus a… Next up
-
19
Setting Up a New Machine
You change an alias on one machine, commit and push your dotfiles, then run
git pullon a second. Is the alias in effect there? The payoff: a new Linux machine gets your whole setup in a few commands, git, an SSH key, clone, install.sh, name and email. Keeping machines in step with commit, push, and pull. Settings for one… Next up