🌍 Git & Version Control · subject
Git & Version Control Core Git Workflow Syllabus
The Core Git Workflow syllabus for Git & Version Control in full: 5 chapters and 18 topics, every one listed below, plus 56 Core Git Workflow flashcards with answers.
Core Git Workflow syllabus: all 5 chapters
Expand any chapter to see its topics and sub-topics.
-
Creating and Cloning Repositories
3 topics- git init
- git clone
- Repository Structure and .gitignore
-
Recording Changes
4 topics- Checking Status with git status
- Staging Changes with git add
- Committing with git commit
- Removing and Moving Files
-
Viewing History
4 topics- git log and Its Options
- Filtering Commit History
- Inspecting Changes with git diff
- git show and git blame
-
Undoing Changes
4 topics- Unstaging and Discarding Changes
- Reverting Commits with git revert
- Resetting with git reset
- Recovering Lost Work with the Reflog
-
Stashing and Cleaning
3 topics- Saving Work with git stash
- Managing Multiple Stashes
- Cleaning the Working Directory with git clean
Git & Version Control Core Git Workflow flashcards — 56 questions with answers
What does the command `git init` do?
It creates a new, empty Git repository in the current directory by generating a hidden `.git` subdirectory that holds all version-control data (objects, refs, config). It does not stage or commit any existing files.
After running `git init` in a folder with existing files, what is the state of those files?
They are present in the working directory but untracked. Git knows nothing about them until you stage them with `git add` and commit them.
What is the purpose of `git clone <url>`?
It copies an existing remote repository to your machine: it creates a directory, initializes a `.git` inside it, downloads the full history, checks out the default branch, and automatically adds the source as a remote named `origin`.
By default, what remote name does `git clone` assign to the source repository?
`origin`.
How do you clone a repository into a directory with a custom name?
`git clone <url> <directory-name>`. The second argument overrides the default directory name derived from the repo URL.
What are the three main states/areas a file can be in within Git's model?
The working directory (modified files), the staging area/index (changes staged for the next commit), and the repository/`.git` directory (committed history).
What does the `.git` directory contain?
All the metadata and object database for the repository: the object store (blobs, trees, commits, tags), refs (branches/tags), HEAD, the index, config, and hooks. Deleting it turns the folder back into an ordinary directory.
What is the purpose of a `.gitignore` file?
It specifies intentionally untracked file patterns that Git should ignore, so they never appear as untracked or get accidentally staged (e.g., build artifacts, logs, secrets, dependency folders).
Does adding a file pattern to `.gitignore` stop Git from tracking a file that is already committed?
No. `.gitignore` only affects untracked files. To stop tracking an already-committed file you must run `git rm --cached <file>` (and then commit) in addition to ignoring it.
In `.gitignore`, what do the patterns `logs/`, `*.log`, and `!important.log` mean?
`logs/` ignores the whole logs directory; `*.log` ignores all files ending in `.log`; `!important.log` is a negation pattern that re-includes `important.log` even though `*.log` would otherwise ignore it.
What does `git status` show?
The current branch, whether it is ahead/behind its upstream, and the state of files: staged changes ready to commit, unstaged modifications, and untracked files.
What does `git status -s` (or `--short`) produce, and how are its two status columns interpreted?
A compact output where each file has a two-letter code: the left column is the staging-area (index) status and the right column is the working-tree status. Codes include `M` modified, `A` added, `D` deleted, `??` untracked.
What does `git add <file>` do?
It stages the current content of the file into the index, marking it to be included in the next commit. It captures a snapshot of the file at the moment `add` is run.
What is the difference between `git add .` and `git add -A`?
`git add -A` (`--all`) stages all changes in the whole repository including deletions, additions, and modifications. `git add .` stages changes in the current directory and below (in modern Git it also includes deletions in that path).
What does `git add -p` (patch mode) let you do?
It lets you interactively review and stage individual hunks (portions) of a file's changes rather than the whole file, so you can craft focused commits.
If you edit a file after staging it with `git add`, what happens in `git status`?
The file appears twice: the previously staged snapshot is listed as staged (to be committed), and the new edits appear as unstaged changes. You must `git add` again to stage the latest edits.
What does `git commit` do?
It permanently records the currently staged snapshot (the index) as a new commit in the repository history, along with an author, timestamp, parent reference, and a commit message.
What does `git commit -m "message"` do?
It commits the staged changes using the given message inline, without opening the configured text editor.
What is the effect of `git commit -a`?
It automatically stages all already-tracked, modified and deleted files and then commits them in one step. It does NOT include untracked (new) files.
What does `git commit --amend` do?
It replaces the most recent commit with a new one, letting you edit its message and/or include newly staged changes. It creates a new commit object with a new hash, so it should not be used on already-pushed public commits.
Show the other 36 Core Git Workflow flashcards
What is the difference between `git rm <file>` and `rm <file>`?
`rm <file>` deletes the file from the working directory only, leaving the deletion unstaged. `git rm <file>` deletes the file AND stages the removal in the index in one step, ready to commit.
What does `git rm --cached <file>` do?
It removes the file from the index (stops tracking it) but leaves the physical file in the working directory. Useful for un-tracking a file you now want to ignore.
How does `git mv old new` compare to using the shell `mv` and then `git add`?
They are equivalent. `git mv old new` is a convenience that runs `mv old new`, then `git rm old` and `git add new`, staging the rename in one command. Git detects renames by content similarity rather than storing an explicit rename.
What does `git log` display by default?
The commit history of the current branch in reverse chronological order (newest first), showing each commit's full SHA-1 hash, author, date, and message.
What does `git log --oneline` show?
A condensed one-line-per-commit view with the abbreviated commit hash and the first line of each commit message.
What do the `--graph`, `--all`, and `--decorate` options add to `git log`?
`--graph` draws an ASCII commit/branch topology; `--all` shows commits from all refs/branches, not just the current one; `--decorate` annotates commits with the branch and tag names pointing to them.
How do you limit `git log` to the last 5 commits?
`git log -5` (or `git log -n 5`).
How do you filter commit history by author?
`git log --author="Name"`, which matches commits whose author field contains the given pattern (regex-capable).
What do `git log --since` and `git log --until` do?
They filter commits by date: `--since="2 weeks ago"` shows commits after that date and `--until="2020-01-01"` shows commits before it. They can be combined to bound a range.
What does `git log --grep="pattern"` filter on?
It shows only commits whose commit message matches the given regular-expression pattern.
What does `git log -- <path>` (or `git log <path>`) do?
It shows only the commits that touched the specified file or directory, filtering the history by path.
What does `git log -S "string"` (the pickaxe) find?
Commits that changed the number of occurrences of the given string in the code (i.e., where the string was added or removed), letting you find when a piece of code appeared or disappeared.
What does plain `git diff` (no arguments) show?
The differences between the working directory and the staging area (index) — i.e., changes you have made but not yet staged.
What does `git diff --staged` (or `--cached`) show?
The differences between the staging area (index) and the last commit (HEAD) — i.e., the changes that are staged and will go into the next commit.
What does `git diff HEAD` show?
All differences between the working directory and the last commit, combining both staged and unstaged changes.
How do you see the differences between two commits with `git diff`?
`git diff <commit1> <commit2>`, which shows the changes needed to transform the first commit's tree into the second's.
What does `git show <commit>` display?
The metadata and content of a single object; for a commit it shows the author, date, message, and the full diff (patch) introduced by that commit.
What does `git blame <file>` show?
A line-by-line annotation of the file indicating, for each line, the commit hash, author, and date of the last revision that modified that line.
What is the difference between `git blame` and `git log`?
`git log` shows commits chronologically (history of the repo/file), whereas `git blame` maps each individual line of a file to the specific commit and author that last changed it.
How do you unstage a file that you have added with `git add` (modern syntax)?
`git restore --staged <file>` (or the older `git reset HEAD <file>`). This removes it from the index while keeping the working-directory changes intact.
How do you discard unstaged changes to a tracked file, reverting it to the last committed version?
`git restore <file>` (or the older `git checkout -- <file>`). This is destructive: the uncommitted changes are lost.
What does `git revert <commit>` do?
It creates a NEW commit that applies the inverse of the changes introduced by the specified commit, undoing its effect while preserving history. It is the safe way to undo a commit that has already been shared/pushed.
How does `git revert` differ from `git reset` conceptually?
`git revert` undoes changes by adding a new inverse commit, keeping history intact (non-destructive, safe for shared branches). `git reset` moves the branch pointer backward, rewriting/removing history (destructive, best for local/unshared commits).
What does the `-n` / `--no-commit` option do with `git revert`?
It applies the inverse changes to the working tree and index but does not create the revert commit automatically, letting you combine or edit before committing yourself.
What are the three modes of `git reset` and how do they differ?
`--soft` moves HEAD only (changes stay staged); `--mixed` (default) moves HEAD and resets the index (changes become unstaged but kept in working dir); `--hard` moves HEAD and resets both index and working directory (changes are discarded).
What does `git reset --hard HEAD~1` do?
It moves the current branch back by one commit and discards all changes from that commit in both the index and working directory. This is destructive and permanently drops those uncommitted changes.
What does `git reset --soft HEAD~1` accomplish?
It undoes the last commit but keeps its changes staged in the index, effectively letting you re-commit them (e.g., to combine or rewrite the commit message).
What is the reflog and what does `git reflog` show?
The reflog is a local log recording every update to the tips of branches and HEAD (commits, resets, checkouts, rebases, etc.). `git reflog` lists these movements with their hashes, enabling recovery of commits that seem lost.
How can you recover a commit after an accidental `git reset --hard`?
Find the lost commit's hash in `git reflog`, then restore it, e.g. `git reset --hard <hash>` or `git checkout <hash>` (or create a branch at it). The reflog retains the reference even though no branch points to it.
What does `git stash` do?
It saves your uncommitted changes (staged and unstaged tracked modifications) onto a stack and reverts the working directory to a clean state matching HEAD, so you can switch context without committing.
How do you reapply the most recent stash, and what is the difference between `git stash pop` and `git stash apply`?
`git stash pop` reapplies the top stash and removes it from the stash stack; `git stash apply` reapplies it but keeps it on the stack so it can be applied again.
How do you view the list of saved stashes and inspect one?
`git stash list` shows all stashes as `stash@{0}`, `stash@{1}`, etc.; `git stash show [-p] stash@{n}` displays its summary or full diff.
How do you apply or drop a specific (non-top) stash from multiple stashes?
Reference it by index, e.g. `git stash apply stash@{2}` to apply it or `git stash drop stash@{2}` to delete it. `git stash clear` removes all stashes.
How do you include untracked files when stashing?
`git stash -u` (or `--include-untracked`) also stashes untracked files; `git stash -a` (`--all`) additionally includes ignored files.
What does `git clean` do, and why does it require a force flag?
It removes untracked files from the working directory. Because deletion is irreversible, Git requires `-f` (`--force`) to actually delete; without it (or a dry-run) it refuses for safety.
What is the difference between `git clean -n`, `git clean -f`, and `git clean -fd`?
`-n` (`--dry-run`) lists what would be removed without deleting; `-f` force-deletes untracked files; `-fd` force-deletes untracked files AND untracked directories. Adding `-x` also removes ignored files.
Git & Version Control Core Git Workflow FAQ
What is in the Git & Version Control Core Git Workflow syllabus?
Git & Version Control Core Git Workflow is split into 5 chapters: Creating and Cloning Repositories, Recording Changes, Viewing History, Undoing Changes and Stashing and Cleaning. Together they contain 18 topics.
How many chapters are in Git & Version Control Core Git Workflow?
5 chapters, containing 18 topics. The largest chapter is Recording Changes, with 4 topics.
Are there flashcards for Git & Version Control Core Git Workflow?
Yes — a 56-card Core Git Workflow deck, printed in full in the flashcards section of this page and available in the Examius app with spaced repetition. The free plan covers one exam of your choice, including its flashcards; Examius Pro, a one-time purchase, unlocks every other exam and deck.