- Home
- Deck Library
- Technology
- Git Command Basics
Git Command Basics
Master the 22 Git commands you use every day with flashcards: what each command does, the difference between similar commands, and the safe way to undo mistakes. Checked against the official Git documentation.
New developers, students in their first team project, and anyone who wants to stop copy-pasting Git commands without understanding them.
Covers everyday local and remote workflow commands (init, clone, add, commit, status, log, diff, branch, checkout/switch, merge, pull, push, stash, reset, revert, tag). Does not cover rebase workflows, submodules, bisect, or server administration.
Flashcard Maker engineering — every command was run in a sample repository and checked against git-scm.com documentation before publishing. Last reviewed: 2026-08-13.
- Git Reference Documentation — git-scm.com (Software Freedom Conservancy)
- Pro Git book (2nd edition) — git-scm.com — Chacon & Straub, Apress
Want spaced-repetition scheduling for this material?
Create a free account, build your own deck in the editor and study it on a schedule based on what you forget.
Start freeAll 22 cards in this deck
- 1. What does `git init` do?Creates a new empty Git repository in the current directory by adding a `.git` folder. It does not create any commits yet.
- 2. What does `git clone <url>` do?Downloads a full copy of a remote repository — all files, branches and history — and sets the remote named `origin` to that URL.
- 3. What does `git status` show?The current branch, staged changes, unstaged changes, and untracked files. It never modifies anything — safe to run anytime.
- 4. What does `git add <file>` actually do?Puts the file’s current contents into the STAGING AREA (index) so it will be included in the next commit. `git add .` stages everything in the current directory.
- 5. What does `git commit -m "message"` do?Records a snapshot of everything in the staging area as a new commit on the current branch, with the given message.
- 6. Difference between `git commit -m` and `git commit -am`?`-a` additionally auto-stages all MODIFIED tracked files before committing. It does NOT include new (untracked) files — those still need `git add`.
- 7. What does `git log --oneline` show?The commit history of the current branch, one commit per line (short hash + message). Add `--graph --all` to see all branches drawn as a graph.
- 8. What does `git diff` show by default, and how do you see staged changes?`git diff` shows UNSTAGED changes (working tree vs index). `git diff --staged` (alias `--cached`) shows what is staged for the next commit.
- 9. What does `git branch <name>` do — does it switch you to the branch?It only CREATES the branch pointing at the current commit. It does not switch; use `git switch <name>` or `git checkout <name>` to move onto it.
- 10. What is the modern replacement for `git checkout <branch>`?`git switch <branch>` (Git 2.23+). `git switch -c <name>` creates and switches in one step, like the old `git checkout -b <name>`.
- 11. What does `git merge <branch>` do?Combines the named branch INTO your current branch. If both branches changed the same lines, Git stops and asks you to resolve conflicts, then commit.
- 12. What is the difference between `git fetch` and `git pull`?`fetch` downloads new remote commits but does NOT change your working branch. `pull` = `fetch` + `merge` (or rebase) into your current branch.
- 13. What does `git push` do, and when does it get rejected?Uploads your local commits to the remote branch. It is rejected when the remote has commits you don’t have — `git pull` first, then push again.
- 14. What does `git stash` do?Shelves your uncommitted changes (staged + unstaged) so the working tree is clean, letting you switch tasks. Bring them back with `git stash pop`.
- 15. Difference between `git stash pop` and `git stash apply`?Both re-apply the latest stash; `pop` also REMOVES it from the stash list, `apply` keeps it there (useful for applying to several branches).
- 16. What does `git restore <file>` do?Discards UNSTAGED changes in that file, restoring it to the last committed (or staged) version. The discarded edits are gone — Git cannot recover them.
- 17. How do you unstage a file without losing its changes?`git restore --staged <file>` (or the older `git reset HEAD <file>`). The edits stay in your working tree; they are just no longer staged.
- 18. What is the difference between `git reset --soft`, `--mixed` and `--hard`?All move the branch pointer. `--soft` keeps changes staged; `--mixed` (default) keeps them unstaged; `--hard` DELETES them from the working tree — destructive.
- 19. When should you use `git revert <commit>` instead of `git reset`?On shared/pushed history. `revert` creates a NEW commit that undoes the old one, so history is never rewritten; `reset` rewrites history and breaks collaborators.
- 20. What does `git remote -v` show?The named remotes of the repository (usually `origin`) with their fetch and push URLs.
- 21. What does `git tag v1.0.0` do, and do tags push automatically?Creates a lightweight tag pointing at the current commit. Tags are NOT pushed by default — use `git push origin v1.0.0` (or `--tags`).
- 22. Why is `git push --force` dangerous, and what is the safer flag?It overwrites remote history, deleting teammates’ commits. `--force-with-lease` refuses to push if the remote has commits you haven’t seen.
Good to know
- •Commands were tested with a recent Git version; older versions may lack `git switch` and `git restore` (introduced in Git 2.23).
- •Destructive commands (`reset --hard`, `push --force`) are flagged on their cards — read the note before using them on shared branches.
Found an error, or content you believe violates our Terms? Email support@onlineflashcardmaker.com — we fix verified reports and update the review date.