</> GIT/VISUAL Map 01 Ch 1 / Part 1 Why Git? The problem Git solves, in pictures 02 Ch 2 / Part 1 Git vs GitHub Two things people mix up. Plus your first win. 03 Ch 3 / Part 1 Your terminal Open one in any folder and move around 04 Ch 4 / Part 1 Install Git (and PATH) Download, install, verify. Windows, macOS, Linux 05 Ch 5 / Part 1 First-time setup Name, email, editor, default branch 06 Ch 6 / Part 2 Your first repository git init, git status, the 3 areas 07 Ch 7 / Part 2 Your first commit add, commit, log 08 Ch 8 / Part 2 See changes, ignore files diff, restore a file, .gitignore 09 Ch 9 / Part 2 Undo and time travel restore, amend, revert, reset, reflog Cheats Lab Ch 1 CHEAT SHEET · 247 COMMANDS · LIVE + REFERENCE Every command, one tap away. Tap a card to open it, then press Run it . The command runs in the same practice sim as the chapters, and the three areas update live. Copy it when you are ready to use it for real.
Safe Careful Can lose work
git statusgit add .git commitgit log
Most used tap to jump git statusgit addgit commit -m "message"git log --onelinegit diffgit restoregit restore --stagedgit reflog
No match. Try a plain word like "undo", "delete" or "history".Clear search
Start Turn a folder into a repo and tell Git who you are git init Make the current folder a Git repository. Git starts watching it. +
git config --global user.name "Your Name" Set the name stamped on every commit. Do it once per computer. +
git --version Check Git is installed and see which version you have. +
git status Ask Git what it sees right now: branch, new files, edits, staged files. +
git config --global user.email "you@example.com" Set the email stamped on every commit. Use the email on your GitHub account. +
git config --list Show every setting Git is using right now. +
git clone <url> Copy a repo from GitHub (or anywhere) to your computer, history included. +
git clone <url> <folder> Clone into a folder name you choose instead of the repo name. +
git config --global user.email "you@example.com" Set the email stamped on every commit. Use the email on your GitHub account. +
git config --global init.defaultBranch main Make every new repo start on a branch called main instead of master. +
git config --global core.editor "code --wait" Pick the editor Git opens for commit messages. This one is VS Code. +
git config --list Show every setting Git is using right now. +
git status -s Short status: two letters per file instead of full sentences. +
git help <command> Open the manual page for a command. git <command> -h gives a quick summary. +
Save work See changes, stage them, snapshot them git add <file> Put one file in the staging area, ready for the next snapshot. +
git add . Stage everything new or changed in this folder (except ignored files). +
git commit -m "message" Save a snapshot of everything staged, with a short message. +
git commit -am "message" Stage every edit to already-tracked files and commit, in one go. Does not add new files. +
git add -A Stage everything: new files, edits and deletions, anywhere in the repo. +
git add -u Stage edits and deletions of files Git already tracks. New files are skipped. +
git add -p Pick which chunks of a file to stage, one by one. Great for tidy commits. +
git add "*.txt" Stage every file that matches a pattern. Quote it so Git does the matching. +
git commit -m "title" -m "details" Add a longer description under the title. Each -m becomes a paragraph. +
git commit Save a snapshot and write the message in your editor. +
git mv <old> <new> Rename or move a file and stage the change in one step. +
History and compare Read the past and compare any two versions git log List past snapshots, newest first, with author, date and message. +
git log --oneline The same history, one short line per commit. Great for a quick look. +
git diff Show edits you have not staged yet. Green lines were added, red removed. +
git diff --staged Show what is staged, which is exactly what the next commit will contain. +
git show Show the latest commit: who, when, the message, and exactly what changed. +
git show <commit> Show any commit: who, when, the message and exactly what changed. HEAD~1 means one before the latest. +
git log --oneline --graph --all Draw every branch as a tree of commits, one line each. +
git log -n 3 Only show the last 3 commits. Change the number to see more or fewer. +
git log --stat History plus a summary of which files each commit touched. +
git log -p History with the full line-by-line changes of every commit. +
git log --author="Ada" Only commits written by someone whose name or email contains Ada. +
git log --since="2 weeks ago" Only commits from the last two weeks. --until works too. +
git log -- <file> History of one file: only commits that touched it. +
git log main..feature Commits that are on feature but not on main yet. +
git diff HEAD All uncommitted changes, staged or not, against the last commit. +
git diff <commit1> <commit2> Compare two snapshots. Works with branch names and tags too. +
git diff --stat Just a summary of what changed: which files and how many lines. +
git diff --name-only Only the names of the files that changed. +
git show <commit> Show any commit: who, when, the message and exactly what changed. +
git blame <file> Show who last changed each line of a file, and in which commit. +
git blame -L 10,20 <file> Blame only lines 10 to 20 of a file. +
git grep "text" Search for text in every tracked file. Fast, and it skips ignored files. +
git shortlog -sn Count commits per person, most active first. +
git ls-files List every file Git is tracking right now. +
git rev-parse HEAD Print the full id of the commit you are on. +
Branches Work on an idea without touching main git branch List your branches. The star marks the one you are on. +
git branch <name> Make a new branch at the commit you are on. It does not switch to it. +
git switch <branch> Move to another branch. Your folder changes to match it. +
git switch -c <name> Make a new branch and move to it in one step. +
git checkout <branch> The older way to switch branches. Still everywhere in tutorials. +
git checkout -b <name> The older way to make a branch and move to it. Same as git switch -c. +
git branch -a List local branches and the ones that exist on the remote. +
git branch -vv List branches with their latest commit and which remote branch they follow. +
git branch --show-current Print only the name of the branch you are on. +
git switch - Jump back to the branch you were on before. Like the back button. +
git branch -m <new-name> Rename the branch you are on. +
git branch -d <name> Delete a branch that is already merged. Git refuses if it is not merged. +
git branch -D <name> Force-delete a branch even if it is not merged. Its unique commits become hard to find. +
git branch --merged List branches that are already merged into the one you are on. Safe to delete. +
git branch --no-merged List branches with work that is not merged yet. +
Merge and rebase Combine branches or copy single commits git merge <branch> Bring another branch's commits into the one you are on. +
git merge --no-ff <branch> Always make a merge commit, so the branch stays visible in history. +
git merge --squash <branch> Fold a whole branch into one staged change. You write the single commit. +
git merge --abort Stop a merge that hit conflicts and go back to how things were. +
git diff --name-only --diff-filter=U List the files that still have merge conflicts. +
git mergetool Open a visual tool to fix conflicts, one file at a time. +
git rebase <branch> Replay your commits on top of another branch for a straight, clean history. +
git rebase -i HEAD~3 Edit, reorder, squash or drop your last 3 commits. Rewrites history. +
git rebase --continue After fixing a rebase conflict and staging the file, carry on. +
git rebase --abort Cancel a rebase and go back to how the branch was before. +
git rebase --skip Drop the commit that is causing a rebase conflict and move on. +
git cherry-pick <commit> Copy one commit from another branch onto the one you are on. +
git cherry-pick --abort Cancel a cherry-pick that hit a conflict. +
git merge-base main feature Find the commit where two branches split apart. +
Remotes and sync Link to GitHub, push, fetch and pull git remote add origin <url> Link your local repo to a repo on GitHub. origin is the usual nickname. +
git remote -v List the remotes this repo knows, with their URLs. +
git remote show origin Details about a remote: its branches and how yours line up. +
git remote set-url origin <url> Point origin at a different URL. Use it to switch from HTTPS to SSH. +
git remote rename origin upstream Give a remote a new nickname. +
git remote remove origin Forget a remote. Your files and history stay. Only the link goes. +
git push Send your new commits to the remote branch you are tracking. +
git push -u origin main First push of a branch. Sends it and remembers it, so later git push works alone. +
git push origin <branch> Push one named branch to the remote. +
git push --force-with-lease Overwrite the remote branch, but only if nobody else pushed since you looked. Safer force. +
git push --force Overwrite the remote branch no matter what. Can erase teammates' commits. +
git push origin --delete <branch> Delete a branch on the remote. Your local copy stays. +
git fetch Download new commits from the remote but do not change your files. +
git fetch --all --prune Fetch from every remote and forget remote branches that were deleted. +
git pull Fetch and merge the remote's new commits into your branch. +
git pull --rebase Pull, then replay your own commits on top. Keeps history in a straight line. +
git branch --set-upstream-to=origin/main Tell your branch which remote branch to follow. +
git remote prune origin Forget remote branches that no longer exist on GitHub. +
git ls-remote <url> List the branches and tags of a remote without cloning it. +
Stash A shelf for half-done work git stash Park your uncommitted edits on a shelf and get a clean folder back. +
git stash push -m "message" Stash with a name, so you can find it later. +
git stash -u Stash new, untracked files too. A plain stash leaves them behind. +
git stash list Show everything on the shelf, newest first. +
git stash show -p See what is inside the newest stash, line by line. +
git stash pop Bring back the newest stash and remove it from the shelf. +
git stash apply Bring back a stash but keep it on the shelf too. +
git stash drop Throw away the newest stash. +
git stash clear Throw away every stash at once. No undo. +
git stash branch <name> Start a new branch from a stash and apply it there. +
Undo Take things back, from gentle to drastic git restore <file> Throw away your unsaved edits to a file and go back to the last commit. Cannot be undone. +
git restore --staged <file> Unstage a file. Your edits stay in the file, they just leave the waiting room. +
git commit --amend -m "new message" Fix the last commit message (or add a forgotten file) by replacing the commit. Only for commits you have not shared. +
git reset --soft HEAD~1 Undo the last commit but keep all its changes staged, ready to commit again. +
git reset --hard HEAD~1 Delete the last commit and its changes from your folder. Unsaved work is gone. The reflog can bring the commit back. +
git revert HEAD --no-edit Make a new commit that cancels an old one. History stays intact, so it is safe for shared work. +
git reflog A diary of everywhere HEAD has been. The way back after a reset. It forgets after a while. +
git reset --hard HEAD@{1} Jump back to where HEAD was one move ago. This rescues a commit you reset away. +
git reset Unstage everything. Your edits stay in your files. +
git reset --mixed HEAD~1 Undo the last commit and unstage its changes. Your files keep the edits. +
git commit --amend --no-edit Add staged changes to the last commit and keep its message. +
git restore . Throw away all unsaved edits to tracked files in this folder. Cannot be undone. +
git restore --source=<commit> <file> Bring one file back to how it looked in an older commit. +
git reset --mixed HEAD~1 Undo the last commit and unstage its changes. Your files keep the edits. +
git revert <commit> Undo one older commit by adding a new commit that cancels it. +
git revert --abort Stop a revert that hit conflicts. +
git revert -m 1 <merge-commit> Undo a merge commit. -m 1 says keep the main line. +
git reset --hard Throw away every uncommitted edit, staged or not. Back to the last commit. +
git reset --hard origin/main Make your branch match the remote exactly. Local commits and edits are lost. +
git switch --detach <commit> Look at an old commit as it was. Nothing changes. Go back with git switch main. +
git checkout <commit> -- <file> Old style way to restore one file from an older commit. +
git clean -n Dry run: list the untracked files git clean would delete. Deletes nothing. +
git clean -fd Delete untracked files and folders for real. There is no trash can. +
git clean -fdx Also delete ignored files, like node_modules. Everything not tracked is gone. +
Ignore and remove Keep files out of Git, or stop tracking them echo "*.log" > .gitignore List patterns of files Git should never track. *.log hides every file ending in .log. +
git rm <file> Delete a tracked file and stage the deletion in one step. +
git rm --cached <file> Stop tracking a file but keep it on disk. Pair it with .gitignore. +
git add -f <file> Force-stage a file even though .gitignore hides it. Use rarely. +
echo "*.log" >> .gitignore Add a rule to the end of .gitignore. A single > would replace the whole file. +
echo "node_modules/" >> .gitignore Add a line to .gitignore. A trailing slash means a whole folder. +
git rm -r <folder> Delete a tracked folder and stage the deletion. +
git rm -r --cached . Untrack everything, keep the files. Then git add . so new .gitignore rules apply. +
git check-ignore -v <file> Find out which .gitignore rule is hiding a file. +
git status --ignored Show ignored files too, so you can see what Git is skipping. +
git config --global core.excludesfile ~/.gitignore_global Ignore files in every repo on this computer, like .DS_Store. +
Sign in to GitHub Logins, SSH keys and the gh sign-in gh auth login Sign in to GitHub from the terminal. Follow the prompts to log in with the browser. +
gh auth status Check whether you are signed in, and as who. +
gh auth setup-git Let git use your gh sign-in, so git push works over HTTPS without asking for a password. +
gh auth logout Sign out of GitHub on this computer. +
gh --version Check the GitHub CLI is installed. +
git config --global credential.helper store Remember your HTTPS login so Git stops asking. Stores it as plain text, so prefer gh auth. +
ssh-keygen -t ed25519 -C "you@example.com" Make an SSH key pair so GitHub knows your computer without a password. +
cat ~/.ssh/id_ed25519.pub Print your public key, then paste it into GitHub: Settings, SSH keys. Never share the file without .pub. +
ssh-add ~/.ssh/id_ed25519 Load your key into the SSH agent so you type the passphrase once. +
ssh -T git@github.com Test that GitHub accepts your SSH key. +
GitHub CLI (gh) Repos, pull requests, issues and releases from the terminal gh repo create <name> --private --source=. --push Create a GitHub repo from the folder you are in and push it. Use --public for a public one. +
gh repo clone <owner/repo> Clone a repo by name. No URL needed. +
gh repo fork --clone Make your own copy of someone else's repo on GitHub and clone it. +
gh repo view --web Open this repo's GitHub page in your browser. +
gh repo view Print the repo's name, description and README in the terminal. +
gh repo list List your repos. +
gh repo delete <owner/repo> Delete a repo on GitHub for good. It asks you to type the name to confirm. +
gh browse Open the repo in your browser. gh browse <file> opens a file. +
gh pr create --fill Open a pull request from your branch. --fill uses your commit messages for the title and text. +
gh pr list List the open pull requests. +
gh pr status Your pull requests and the ones waiting on your review. +
gh pr view <number> --web Open a pull request in your browser. +
gh pr checkout <number> Download someone's pull request branch so you can test it. +
gh pr diff <number> See what a pull request changes, in the terminal. +
gh pr review <number> --approve Approve a pull request. Use --request-changes or --comment for other replies. +
gh pr merge <number> --squash --delete-branch Merge a pull request as one commit and delete its branch. Also --merge or --rebase. +
gh pr close <number> Close a pull request without merging it. +
gh pr comment <number> --body "text" Leave a comment on a pull request. +
gh issue create --title "Bug" --body "What happened" Open a new issue from the terminal. +
gh issue list List open issues. +
gh issue view <number> Read one issue, with its comments. +
gh issue close <number> Close an issue. +
gh release create v1.0.0 --generate-notes Publish a release on GitHub from a tag, with notes written from your merged pull requests. +
gh release list List the releases of this repo. +
gh run list List recent GitHub Actions runs and whether they passed. +
gh run watch Follow a running workflow live until it finishes. +
gh workflow run <file> Start a workflow by hand. The workflow must allow manual runs. +
gh gist create <file> Share a file as a GitHub gist. Add --public to make it public. +
Power tools Submodules, worktrees, bisect and housekeeping git config --global alias.st status Make your own shortcut. After this, git st means git status. +
git config --global --edit Open your global Git settings file in your editor. +
git submodule add <url> <path> Put another repo inside yours, pinned to one commit. +
git submodule update --init --recursive Download the submodules of a repo you just cloned. +
git submodule status List submodules and the commit each one is on. +
git clone --recurse-submodules <url> Clone a repo and its submodules together. +
git worktree add ../hotfix hotfix Check out a second branch in its own folder, without stashing your work. +
git worktree list List the folders linked to this repo. +
git worktree remove <path> Delete a linked worktree folder. +
git bisect start Begin a hunt for the commit that broke something. Git does a binary search. +
git bisect bad Tell bisect the commit you are on is broken. +
git bisect good <commit> Tell bisect a commit that worked. It checks out the middle for you to test. +
git bisect reset Stop bisecting and go back to the branch you were on. +
git fsck --lost-found Look for commits no branch points to. Last-resort recovery after a reflog expires. +
git gc Tidy up and compress the repo's storage. Rarely needed. +
git count-objects -vH Show how much space the repo uses. +
git archive --format=zip -o out.zip HEAD Pack the latest snapshot into a zip, without the .git folder. +
git rev-parse --show-toplevel Print the path of the repo's main folder. +
git commit --fixup <commit> Make a small fix-up commit meant to be folded into an older one. +
git rebase -i --autosquash <commit> Fold your fixup commits into the commits they belong to. Rewrites history. +
git commit --no-verify Skip the pre-commit checks. Use only when you must. +
git cat-file -p HEAD Peek at a raw commit object inside the .git folder. +
git ls-tree HEAD List the files and folders stored in a commit. +
git lfs install Turn on Git LFS, which stores big files outside the normal history. +
git lfs track "*.psd" Send every .psd file through Git LFS from now on. +
Terminal basics The shell commands under every Git command pwd Print the folder you are in. +
ls List the files and folders here. +
ls -a List everything, including hidden files such as .git and .gitignore. +
cd <folder> Move into a folder. cd .. goes up one level. cd alone goes home. +
mkdir <name> Make a new folder. +
touch <file> Make an empty file. +
echo "text" > file Write text into a file. > replaces the file, >> adds to the end. +
cat <file> Print what is inside a file. +
rm <file> Delete a file. There is no trash can. It is gone. +
clear Wipe the screen. Your files and history are untouched. +
mkdir -p <a/b/c> Make a folder and any missing folders above it. +
rm -r <folder> Delete a folder and everything inside it. There is no trash can. +
cd .. Go up one folder. +
cd ~ Go to your home folder from anywhere. +
ls -l List files one per line with size and date. +
ls -la Everything, hidden files too, with details. +
cp <source> <copy> Copy a file. +
cp -r <folder> <copy> Copy a whole folder with everything in it. +
mv <old> <new> Rename a file or move it. It overwrites without asking if the new name exists. +
rmdir <folder> Remove an empty folder. It refuses if the folder has files. +
head -n 5 <file> Print the first 5 lines of a file. +
tail -n 5 <file> Print the last 5 lines of a file. +
less <file> Read a long file page by page. Space goes down, q quits. +
grep "text" <file> Find the lines in a file that contain some text. +
grep -r "text" . Search for text in every file under this folder. +
which git Show where the git program lives. On Windows cmd use where git. +
echo $PATH Print the list of folders your terminal searches for programs. +
history List the commands you ran before. Press the up arrow to reuse one. +
code . Open this folder in VS Code. open . does it in Finder on macOS, explorer . on Windows. +
exit Close the terminal session. +
About the practice sim Cards marked Runs live execute in the practice sim, so you can try them safely. The others are Reference cards: they show what you will see on a real computer. Commands that talk to GitHub need an internet connection and a sign-in, so they are reference only. Always run git status before anything marked Can lose work.